From 320cb344c14b30f8c1aa8c2d86803e4c2f971ae9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:31:37 +0100 Subject: docs(api): link to nvim_set_hl_ns from nvim_set_hl (#22678) --- src/nvim/api/window.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index e2c234ab29..abe11e6b72 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -445,8 +445,9 @@ Object nvim_win_call(Window window, LuaRef fun, Error *err) return res; } -/// Set highlight namespace for a window. This will use highlights defined in -/// this namespace, but fall back to global highlights (ns=0) when missing. +/// Set highlight namespace for a window. This will use highlights defined with +/// |nvim_set_hl()| for this namespace, but fall back to global highlights (ns=0) when +/// missing. /// /// This takes precedence over the 'winhighlight' option. /// -- cgit From a3751f5de22f7780d25cca77b23e690915a789a9 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 1 Jun 2023 11:44:08 +0200 Subject: fix(api): dont change curwin for nvim_win_set_height --- src/nvim/api/window.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index abe11e6b72..bc6d40acc3 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -167,13 +167,8 @@ void nvim_win_set_height(Window window, Integer height, Error *err) return; } - win_T *savewin = curwin; - curwin = win; - curbuf = curwin->w_buffer; try_start(); - win_setheight((int)height); - curwin = savewin; - curbuf = curwin->w_buffer; + win_setheight_win((int)height, win); try_end(err); } -- cgit From 1ff4562502e146d6da051b1adae925197b418493 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 1 Jun 2023 12:42:06 +0200 Subject: fix(api): dont change curwin for nvim_win_set_width --- src/nvim/api/window.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index bc6d40acc3..c021fec220 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -209,13 +209,8 @@ void nvim_win_set_width(Window window, Integer width, Error *err) return; } - win_T *savewin = curwin; - curwin = win; - curbuf = curwin->w_buffer; try_start(); - win_setwidth((int)width); - curwin = savewin; - curbuf = curwin->w_buffer; + win_setwidth_win((int)width, win); try_end(err); } -- cgit From cee981bf09c81ab4b2fe6facf45076ea4bac46a5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 19 Jun 2023 02:24:44 -0700 Subject: docs #22363 Co-authored by: zeertzjq Co-authored by: Steven Todd McIntyre II <114119064+stmii@users.noreply.github.com> Co-authored by: nobe4 - docs: mention --luadev-mod to run with lua runtime files When changing a lua file in the ./runtime folder, a new contributor might expect changes to be applied to the built Neovim binary. --- src/nvim/api/window.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index c021fec220..97bf0f377a 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -57,6 +57,8 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) /// (different windows showing the same buffer have independent cursor /// positions). |api-indexing| /// +/// @see |getcurpos()| +/// /// @param window Window handle, or 0 for current window /// @param[out] err Error details, if any /// @return (row, col) tuple -- cgit From 4e6356559c8cd44dbcaa765d1f39e176064526ec Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 22 Jun 2023 03:44:51 -0700 Subject: test: spellcheck :help (vimdoc) files #24109 Enforce consistent terminology (defined in `gen_help_html.lua:spell_dict`) for common misspellings. This does not spellcheck English in general (perhaps a future TODO, though it may be noisy). --- src/nvim/api/window.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 97bf0f377a..e5a824fec9 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -412,11 +412,11 @@ void nvim_win_close(Window window, Boolean force, Error *err) /// @see |nvim_buf_call()| /// /// @param window Window handle, or 0 for current window -/// @param fun Function to call inside the window (currently lua callable +/// @param fun Function to call inside the window (currently Lua callable /// only) /// @param[out] err Error details, if any -/// @return Return value of function. NB: will deepcopy lua values -/// currently, use upvalues to send lua references in and out. +/// @return Return value of function. NB: will deepcopy Lua values +/// currently, use upvalues to send Lua references in and out. Object nvim_win_call(Window window, LuaRef fun, Error *err) FUNC_API_SINCE(7) FUNC_API_LUA_ONLY -- cgit From 77118d0da8badc4135be430f4cbb15bc95bc760f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 20 Apr 2023 21:17:25 +0100 Subject: fix(api): use text_locked() to check textlock Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in #22634 that made functions checking textlock usable in `` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK. --- src/nvim/api/window.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index e5a824fec9..5fb07ecbc8 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -48,7 +48,7 @@ Buffer nvim_win_get_buf(Window window, Error *err) /// @param[out] err Error details, if any void nvim_win_set_buf(Window window, Buffer buffer, Error *err) FUNC_API_SINCE(5) - FUNC_API_CHECK_TEXTLOCK + FUNC_API_TEXTLOCK { win_set_buf(window, buffer, false, err); } @@ -351,7 +351,7 @@ Boolean nvim_win_is_valid(Window window) /// @param[out] err Error details, if any void nvim_win_hide(Window window, Error *err) FUNC_API_SINCE(7) - FUNC_API_CHECK_TEXTLOCK + FUNC_API_TEXTLOCK { win_T *win = find_window_by_handle(window, err); if (!win) { @@ -383,7 +383,7 @@ void nvim_win_hide(Window window, Error *err) /// @param[out] err Error details, if any void nvim_win_close(Window window, Boolean force, Error *err) FUNC_API_SINCE(6) - FUNC_API_CHECK_TEXTLOCK + FUNC_API_TEXTLOCK_ALLOW_CMDWIN { win_T *win = find_window_by_handle(window, err); if (!win) { -- cgit From db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 11 Jul 2023 07:15:46 +0800 Subject: feat(api): add nvim_win_text_height (#24236) It uses the same code as "scroll_delta" of "win_viewport" UI event to calculate text height, but is more flexible. --- src/nvim/api/window.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 5fb07ecbc8..07aad2cd88 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -8,6 +8,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" +#include "nvim/api/private/validate.h" #include "nvim/api/window.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" @@ -20,6 +21,7 @@ #include "nvim/lua/executor.h" #include "nvim/memline_defs.h" #include "nvim/move.h" +#include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/types.h" #include "nvim/window.h" @@ -462,3 +464,104 @@ void nvim_win_set_hl_ns(Window window, Integer ns_id, Error *err) win->w_hl_needs_update = true; redraw_later(win, UPD_NOT_VALID); } + +/// Computes the number of screen lines occupied by a range of text in a given window. +/// Works for off-screen text and takes folds into account. +/// +/// Diff filler or virtual lines above a line are counted as a part of that line, +/// unless the line is on "start_row" and "start_vcol" is specified. +/// +/// Diff filler or virtual lines below the last buffer line are counted in the result +/// when "end_row" is omitted. +/// +/// Line indexing is similar to |nvim_buf_get_text()|. +/// +/// @param window Window handle, or 0 for current window. +/// @param opts Optional parameters: +/// - start_row: Starting line index, 0-based inclusive. +/// When omitted start at the very top. +/// - end_row: Ending line index, 0-based inclusive. +/// When omitted end at the very bottom. +/// - start_vcol: Starting virtual column index on "start_row", +/// 0-based inclusive, rounded down to full screen lines. +/// When omitted include the whole line. +/// - end_vcol: Ending virtual column index on "end_row", +/// 0-based exclusive, rounded up to full screen lines. +/// When omitted include the whole line. +/// @return The number of screen lines that the range of text occupy. +/// +/// @see |virtcol()| for text width. +Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *err) + FUNC_API_SINCE(12) +{ + win_T *const win = find_window_by_handle(window, err); + if (!win) { + return NIL; + } + buf_T *const buf = win->w_buffer; + const linenr_T line_count = buf->b_ml.ml_line_count; + + linenr_T start_lnum = 1; + linenr_T end_lnum = line_count; + int64_t start_vcol = -1; + int64_t end_vcol = -1; + + bool oob = false; + + if (HAS_KEY(opts->start_row)) { + VALIDATE_T("start_row", kObjectTypeInteger, opts->start_row.type, { + return NIL; + }); + start_lnum = (linenr_T)normalize_index(buf, opts->start_row.data.integer, false, &oob); + } + + if (HAS_KEY(opts->end_row)) { + VALIDATE_T("end_row", kObjectTypeInteger, opts->end_row.type, { + return NIL; + }); + end_lnum = (linenr_T)normalize_index(buf, opts->end_row.data.integer, false, &oob); + } + + VALIDATE(!oob, "%s", "Line index out of bounds", { + return NIL; + }); + VALIDATE((start_lnum <= end_lnum), "%s", "'start_row' is higher than 'end_row'", { + return NIL; + }); + + if (HAS_KEY(opts->start_vcol)) { + VALIDATE(HAS_KEY(opts->start_row), "%s", "'start_vcol' specified without 'start_row'", { + return NIL; + }); + VALIDATE_T("start_vcol", kObjectTypeInteger, opts->start_vcol.type, { + return NIL; + }); + start_vcol = opts->start_vcol.data.integer; + VALIDATE_RANGE((start_vcol >= 0 && start_vcol <= MAXCOL), "start_vcol", { + return NIL; + }); + } + + if (HAS_KEY(opts->end_vcol)) { + VALIDATE(HAS_KEY(opts->end_row), "%s", "'end_vcol' specified without 'end_row'", { + return NIL; + }); + VALIDATE_T("end_vcol", kObjectTypeInteger, opts->end_vcol.type, { + return NIL; + }); + end_vcol = opts->end_vcol.data.integer; + VALIDATE_RANGE((end_vcol >= 0 && end_vcol <= MAXCOL), "end_vcol", { + return NIL; + }); + } + + if (start_lnum == end_lnum && start_vcol >= 0 && end_vcol >= 0) { + VALIDATE((start_vcol <= end_vcol), "%s", "'start_vcol' is higher than 'end_vcol'", { + return NIL; + }); + } + + const int64_t res = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol) + + (HAS_KEY(opts->end_row) ? 0 : win_get_fill(win, line_count + 1)); + return INTEGER_OBJ(res); +} -- cgit From abe39f2b243dc813456225a779fbeb7ae6affc27 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Jul 2023 18:02:53 +0800 Subject: feat(api)!: change return type of nvim_win_text_height to Dict (#24365) --- src/nvim/api/window.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 07aad2cd88..5480584aa5 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -488,15 +488,20 @@ void nvim_win_set_hl_ns(Window window, Integer ns_id, Error *err) /// - end_vcol: Ending virtual column index on "end_row", /// 0-based exclusive, rounded up to full screen lines. /// When omitted include the whole line. -/// @return The number of screen lines that the range of text occupy. +/// @return Dictionary containing text height information, with these keys: +/// - all: The total number of screen lines occupied by the range. +/// - fill: The number of diff filler or virtual lines among them. /// /// @see |virtcol()| for text width. -Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *err) +Dictionary nvim_win_text_height(Window window, Dict(win_text_height) *opts, Arena *arena, + Error *err) FUNC_API_SINCE(12) { + Dictionary rv = arena_dict(arena, 2); + win_T *const win = find_window_by_handle(window, err); if (!win) { - return NIL; + return rv; } buf_T *const buf = win->w_buffer; const linenr_T line_count = buf->b_ml.ml_line_count; @@ -510,58 +515,65 @@ Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *e if (HAS_KEY(opts->start_row)) { VALIDATE_T("start_row", kObjectTypeInteger, opts->start_row.type, { - return NIL; + return rv; }); start_lnum = (linenr_T)normalize_index(buf, opts->start_row.data.integer, false, &oob); } if (HAS_KEY(opts->end_row)) { VALIDATE_T("end_row", kObjectTypeInteger, opts->end_row.type, { - return NIL; + return rv; }); end_lnum = (linenr_T)normalize_index(buf, opts->end_row.data.integer, false, &oob); } VALIDATE(!oob, "%s", "Line index out of bounds", { - return NIL; + return rv; }); VALIDATE((start_lnum <= end_lnum), "%s", "'start_row' is higher than 'end_row'", { - return NIL; + return rv; }); if (HAS_KEY(opts->start_vcol)) { VALIDATE(HAS_KEY(opts->start_row), "%s", "'start_vcol' specified without 'start_row'", { - return NIL; + return rv; }); VALIDATE_T("start_vcol", kObjectTypeInteger, opts->start_vcol.type, { - return NIL; + return rv; }); start_vcol = opts->start_vcol.data.integer; VALIDATE_RANGE((start_vcol >= 0 && start_vcol <= MAXCOL), "start_vcol", { - return NIL; + return rv; }); } if (HAS_KEY(opts->end_vcol)) { VALIDATE(HAS_KEY(opts->end_row), "%s", "'end_vcol' specified without 'end_row'", { - return NIL; + return rv; }); VALIDATE_T("end_vcol", kObjectTypeInteger, opts->end_vcol.type, { - return NIL; + return rv; }); end_vcol = opts->end_vcol.data.integer; VALIDATE_RANGE((end_vcol >= 0 && end_vcol <= MAXCOL), "end_vcol", { - return NIL; + return rv; }); } if (start_lnum == end_lnum && start_vcol >= 0 && end_vcol >= 0) { VALIDATE((start_vcol <= end_vcol), "%s", "'start_vcol' is higher than 'end_vcol'", { - return NIL; + return rv; }); } - const int64_t res = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol) - + (HAS_KEY(opts->end_row) ? 0 : win_get_fill(win, line_count + 1)); - return INTEGER_OBJ(res); + int64_t fill = 0; + int64_t all = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol, &fill); + if (!HAS_KEY(opts->end_row)) { + const int64_t end_fill = win_get_fill(win, line_count + 1); + fill += end_fill; + all += end_fill; + } + PUT_C(rv, "all", INTEGER_OBJ(all)); + PUT_C(rv, "fill", INTEGER_OBJ(fill)); + return rv; } -- cgit From 6b4970f6e0ac36021b2a8bd0533f5078040d31f7 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 23 Jul 2023 19:50:20 +0100 Subject: feat(api): allow open_win/win_set_buf in the cmdwin in some cases Problem: As discussed on Matrix, there was some interest in having `nvim_open_win` again be able to open floats in the cmdwin (e.g: displaying a hover doc related to what's in the cmdwin). After #23228, this was disallowed. Solution: Allow `nvim_open_win` in the cmdwin as long as `!enter` and `buffer != curbuf` (the former can cause all sorts of issues, and the latter can crash Nvim after closing cmdwin). Also allow `nvim_win_set_buf` in a similar fashion. Note that we're not *entirely* sure if this is 100% safe (cmdwin is a global-state-using-main-loop-calling beast), but this seems to work OK..? Also: - Check the buffer argument of `nvim_open_win` earlier, and abort if it's invalid (it used to still open a window in this case). - Untranslate `e_cmdwin` errors in the API (other errors in the API are not translated: although not detailed in the API contract yet, errors are supposed to be stable). --- src/nvim/api/window.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 5480584aa5..666f09e890 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -50,9 +50,18 @@ Buffer nvim_win_get_buf(Window window, Error *err) /// @param[out] err Error details, if any void nvim_win_set_buf(Window window, Buffer buffer, Error *err) FUNC_API_SINCE(5) - FUNC_API_TEXTLOCK + FUNC_API_TEXTLOCK_ALLOW_CMDWIN { - win_set_buf(window, buffer, false, err); + win_T *win = find_window_by_handle(window, err); + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!win || !buf) { + return; + } + if (cmdwin_type != 0 && (win == curwin || buf == curbuf)) { + api_set_error(err, kErrorTypeException, "%s", e_cmdwin); + return; + } + win_set_buf(win, buf, false, err); } /// Gets the (1,0)-indexed, buffer-relative cursor position for a given window @@ -396,7 +405,7 @@ void nvim_win_close(Window window, Boolean force, Error *err) if (win == curwin) { cmdwin_result = Ctrl_C; } else { - api_set_error(err, kErrorTypeException, "%s", _(e_cmdwin)); + api_set_error(err, kErrorTypeException, "%s", e_cmdwin); } return; } -- cgit From 5d921e28c1cc33eced22bbfa823460ca241e3dc1 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 23 Jul 2023 23:10:28 +0100 Subject: feat(api): allow win_close in cmdwin to close wins except previous Disallow closing the previous window from `nvim_win_close`, as this will cause issues. Again, no telling how safe this is. It also requires exposing old_curwin. :/ Also note that it's possible for the `&cmdheight` to change if, for example, there are 2 tabpages and `nvim_win_close` is used to close the last window in the other tabpage while `&stal` is 1. This is addressed in a later commit. --- src/nvim/api/window.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 666f09e890..350d934825 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -404,10 +404,11 @@ void nvim_win_close(Window window, Boolean force, Error *err) if (cmdwin_type != 0) { if (win == curwin) { cmdwin_result = Ctrl_C; - } else { + return; + } else if (win == cmdwin_old_curwin) { api_set_error(err, kErrorTypeException, "%s", e_cmdwin); + return; } - return; } tabpage_T *tabpage = win_find_tabpage(win); -- cgit From 472271199e483d3f23d62c272b20c5290eec5474 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 24 Jul 2023 14:19:01 +0100 Subject: feat(api): allow win_hide to close cmdwin or non-previous windows This aligns its behaviour better with `nvim_win_close`. Note that `:hide` is actually incapable of closing the cmdwin, unlike `:close` and `:quit`, so this is a bit of a difference in behaviour. --- src/nvim/api/window.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 350d934825..f32a7e671d 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -362,10 +362,10 @@ Boolean nvim_win_is_valid(Window window) /// @param[out] err Error details, if any void nvim_win_hide(Window window, Error *err) FUNC_API_SINCE(7) - FUNC_API_TEXTLOCK + FUNC_API_TEXTLOCK_ALLOW_CMDWIN { win_T *win = find_window_by_handle(window, err); - if (!win) { + if (!win || !can_close_in_cmdwin(win, err)) { return; } @@ -397,20 +397,10 @@ void nvim_win_close(Window window, Boolean force, Error *err) FUNC_API_TEXTLOCK_ALLOW_CMDWIN { win_T *win = find_window_by_handle(window, err); - if (!win) { + if (!win || !can_close_in_cmdwin(win, err)) { return; } - if (cmdwin_type != 0) { - if (win == curwin) { - cmdwin_result = Ctrl_C; - return; - } else if (win == cmdwin_old_curwin) { - api_set_error(err, kErrorTypeException, "%s", e_cmdwin); - return; - } - } - tabpage_T *tabpage = win_find_tabpage(win); TryState tstate; try_enter(&tstate); -- cgit From 7bc93e0e2f246dd78026a3472d929a0fe450f70d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 14:01:19 +0200 Subject: refactor(api): use typed keysets Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata --- src/nvim/api/window.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f32a7e671d..f74071a002 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -7,6 +7,7 @@ #include #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" #include "nvim/api/window.h" @@ -513,18 +514,12 @@ Dictionary nvim_win_text_height(Window window, Dict(win_text_height) *opts, Aren bool oob = false; - if (HAS_KEY(opts->start_row)) { - VALIDATE_T("start_row", kObjectTypeInteger, opts->start_row.type, { - return rv; - }); - start_lnum = (linenr_T)normalize_index(buf, opts->start_row.data.integer, false, &oob); + if (HAS_KEY(opts, win_text_height, start_row)) { + start_lnum = (linenr_T)normalize_index(buf, opts->start_row, false, &oob); } - if (HAS_KEY(opts->end_row)) { - VALIDATE_T("end_row", kObjectTypeInteger, opts->end_row.type, { - return rv; - }); - end_lnum = (linenr_T)normalize_index(buf, opts->end_row.data.integer, false, &oob); + if (HAS_KEY(opts, win_text_height, end_row)) { + end_lnum = (linenr_T)normalize_index(buf, opts->end_row, false, &oob); } VALIDATE(!oob, "%s", "Line index out of bounds", { @@ -534,27 +529,23 @@ Dictionary nvim_win_text_height(Window window, Dict(win_text_height) *opts, Aren return rv; }); - if (HAS_KEY(opts->start_vcol)) { - VALIDATE(HAS_KEY(opts->start_row), "%s", "'start_vcol' specified without 'start_row'", { + if (HAS_KEY(opts, win_text_height, start_vcol)) { + VALIDATE(HAS_KEY(opts, win_text_height, start_row), + "%s", "'start_vcol' specified without 'start_row'", { return rv; }); - VALIDATE_T("start_vcol", kObjectTypeInteger, opts->start_vcol.type, { - return rv; - }); - start_vcol = opts->start_vcol.data.integer; + start_vcol = opts->start_vcol; VALIDATE_RANGE((start_vcol >= 0 && start_vcol <= MAXCOL), "start_vcol", { return rv; }); } - if (HAS_KEY(opts->end_vcol)) { - VALIDATE(HAS_KEY(opts->end_row), "%s", "'end_vcol' specified without 'end_row'", { - return rv; - }); - VALIDATE_T("end_vcol", kObjectTypeInteger, opts->end_vcol.type, { + if (HAS_KEY(opts, win_text_height, end_vcol)) { + VALIDATE(HAS_KEY(opts, win_text_height, end_row), + "%s", "'end_vcol' specified without 'end_row'", { return rv; }); - end_vcol = opts->end_vcol.data.integer; + end_vcol = opts->end_vcol; VALIDATE_RANGE((end_vcol >= 0 && end_vcol <= MAXCOL), "end_vcol", { return rv; }); @@ -568,7 +559,7 @@ Dictionary nvim_win_text_height(Window window, Dict(win_text_height) *opts, Aren int64_t fill = 0; int64_t all = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol, &fill); - if (!HAS_KEY(opts->end_row)) { + if (!HAS_KEY(opts, win_text_height, end_row)) { const int64_t end_fill = win_get_fill(win, line_count + 1); fill += end_fill; all += end_fill; -- cgit From 22d9338afceae5f8ef3845f152dea07a19d512d1 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 17 Aug 2023 00:53:10 +0100 Subject: fix(api): disallow win_set_buf from changing cmdwin's old curbuf (#24745) A command typed in the cmdwin and executed with `` is expected to be executed in the context of the old curwin/buf, so it shouldn't be changed. --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f74071a002..001797add5 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -58,7 +58,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) if (!win || !buf) { return; } - if (cmdwin_type != 0 && (win == curwin || buf == curbuf)) { + if (cmdwin_type != 0 && (win == curwin || win == cmdwin_old_curwin || buf == curbuf)) { api_set_error(err, kErrorTypeException, "%s", e_cmdwin); return; } -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/api/window.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 001797add5..53095ab019 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -6,12 +6,12 @@ #include #include +#include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" -#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" #include "nvim/api/window.h" -#include "nvim/ascii.h" +#include "nvim/autocmd.h" #include "nvim/buffer_defs.h" #include "nvim/cursor.h" #include "nvim/drawscreen.h" @@ -20,7 +20,8 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/lua/executor.h" -#include "nvim/memline_defs.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/move.h" #include "nvim/plines.h" #include "nvim/pos.h" -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/api/window.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 53095ab019..9a788e9ce4 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/api/window.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 9a788e9ce4..08cd6f881f 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -14,6 +14,7 @@ #include "nvim/drawscreen.h" #include "nvim/eval/window.h" #include "nvim/ex_docmd.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/lua/executor.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 08cd6f881f..1fb7eaba95 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -22,7 +22,7 @@ #include "nvim/message.h" #include "nvim/move.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/types.h" #include "nvim/window.h" -- cgit From e38a05369293293b5b510b1b0014fcc2e7cb87f4 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:46:03 +0100 Subject: build(IWYU): export generated headers --- src/nvim/api/window.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 1fb7eaba95..44c1c5595c 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -5,6 +5,7 @@ #include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" #include "nvim/api/window.h" -- cgit From e3f735ef101d670555f44226614a5c3557053b1f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:13:32 +0100 Subject: refactor: fix includes for api/autocmd.h --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 44c1c5595c..15460ec368 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -3,7 +3,7 @@ #include #include -#include "nvim/api/keysets.h" +#include "nvim/api/keysets_defs.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 15460ec368..de5b40940f 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -24,7 +24,7 @@ #include "nvim/move.h" #include "nvim/plines.h" #include "nvim/pos_defs.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/window.h" /// Gets the current buffer in a window -- cgit