aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
Commit message (Collapse)AuthorAge
* fix(api): nvim_buf_call() from expression for window in non-current tabpage ↵Justin M. Keyes2026-10-14
| | | | | | | | | | | | | | | | #42352 Problem: - nvim_buf_call() aborts (assert) when called from an expression evaluated for a window in another tabpage ('foldexpr', 'statusline'), because `curwin` is not in `curtab`. - After it returns, `curwin` is wrong if it switched windows. - `vim._with{win=…, keepcwd=true}` does not undo `:lcd` if `win` is in another tabpage. Solution: - Allow `curwin` outside `curtab`, and restore if it was outside `curtab` at `ctx_switch()`. - Find the target window in any tabpage when restoring its dirs.
* vim-patch:9.2.1174: fixed-sized windows grow when closing other windows (#42314)zeertzjq2026-10-12
| | | | | | | | | | | | | Problem: Fixed-size windows are resized when sharing free space to a group of windows. Solution: When resizing a group of windows, skip windows with a fixed size if possible (Aryan). fixes: vim/vim#21478 closes: vim/vim#21479 https://github.com/vim/vim/commit/354c4c0d04c3524b74f8ce6175efebda6cfa4c67 Co-authored-by: Aryan <ether9095cable@gmail.com>
* fix(api): preserve option trust during mergesLewis Russell2026-09-22
| | | | | | | | | | | | | Problem: API append, prepend, and remove operations reach the option setter as full replacements. This can clear an expression's untrusted flag and allow it to write files, unlike equivalent :set operations. Solution: Pass replacement status through the option setters so merges preserve the existing value's trust restrictions. AI-assisted
* refactor(option): simplify error buffer handlingLewis Russell2026-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Option validators and setters repeatedly pass error buffers and their sizes separately. Some setters return messages in static storage. Solution: - Add CharBuf for borrowed writable storage, with its length including space for a terminating NUL. - Move option error buffers to the callers that report errors. Preserve existing buffer sizes, truncation, and calls that do not need a message. - Consolidate option error formatting and the duplicated code that lists valid option values. - Return error messages directly from do_one_set_option(). - Remove unused arguments from get_option_newval() and set_option_value_for(). - Handle legacy TTY assignments in the existing callers and remove the redundant compatibility wrapper. - Reuse CharBuf for Tree-sitter query errors. - Pass CharBuf through the statusline and statuscolumn builders, retaining the buffer sizes provided by their callers, including title formatting. AI-assisted
* feat(api): add ev.win to autocmd callback args #39826glepnir2026-09-09
| | | | | | | | Problem: Autocmd callbacks currently have to rely on curwin, which may already have changed by the time they run. This is especially noticeable for WinNew, WinClosed, WinResized and WinScrolled. Solution: Track the window in the autocmd context and expose it as ev.win. Pass it explicitly for the window events that need it.
* fix(ui): too many win_float_pos events for the popupmenu (partial fix)bfredl2026-08-27
| | | | | | | | | | | | | | | | | | | | I got annoyed about so many repeated `win_float_pos` events for the popupmenu. This fixes some of them but not all of them. vibe-less explanation: `need_highlight_changed = true` is very expensive should not be needed when using a window-local highlight namespace. This was only necessary when overriding the global highlight namespace. This can instead be handled by using the correct `hl_attr_active` instead of `highlight_attr`. Also `pum_grid.pending_comp_index_update` can be cleared when using win_float_pos prior to redraw. I wanted to add a test for no repeated win_float_pos event in the same redraw:flush cycle but that requires deeper cleanups, like getting rid of crazy redraw panic intermingled deep into insexpand.c (if "state" is correct, a single update_screen() after the weird multilayer recursive dance should be enough.)
* fix(window): crash when closing new curwin during CTRL-W_x (#41378)zeertzjq2026-08-19
| | | | | Problem: Crash when closing the new current window during CTRL-W_x. Solution: Remove a duplicate redraw of a window that should normally be already mark for redraw in the previous call.
* vim-patch:9.2.0923: tabpage: closing a tab page loses the alternate tab page ↵zeertzjq2026-08-08
| | | | | | | | | | | | | | | | | (#41229) Problem: Closing the current tab page resets the alternate tab page, even when that is another tab page which still exists, so that CTRL-Tab stops working (igorlfs). Solution: Restore the last used tab page after entering another one to close the current one (Hirohito Higashi). related: vim/vim#20965 closes: vim/vim#20973 https://github.com/vim/vim/commit/a05bd64c1dcde65006997efe0ff5ae6b8a9aa382 Co-authored-by: Hirohito Higashi <h.east.727@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* refactor(path): pathcmp() #41035tao2026-08-07
| | | | | | | | | | | | | | | | | | | | | | Problem: Redudant code Solution: Add `path_fold_char()` to normalize path sep. Refactor `pathcmp()` and `path_fnamencmp()` into `path_cmp`. | feature | pathcmp | path_fnamencmp | path_cmp(now) | | ------------------------ | -------------- | -------------- | ------------- | | case folding | `mb_toupper()` | `utf_fold()` | `utf_fold()` | | consults fileignorecase | ✅ | ✅ | `ic` param | | `maxlen` | ✅ | ✅ | ✅ | | `/` == `\` | ✅ | ✅ | ✅ | | MSWIN drive letter | ❌ | ✅ | ✅ | | sep affects sorting | ✅ | ❌ | ✅ | | ignores a trailing slash | ✅ | ❌ | ✅ | Refactor `path_fnamecmp` and `path_full_compare` into `path_equal`, with flags controlling "no filesystem" comparison (i.e. `path_cmp`), env variables expansion, absolute path resolution and filesystem access.
* fix(cwd): :bcd lost by nvim_win_set_buf, nvim_open_win #41218Erdiansyah2026-08-07
| | | | | | | | | | | | Problem: :bcd (buffer-local directory) is not preserved after `nvim_open_win` or `nvim_win_set_buf` Analysis: set_curbuf() ends with update_cwd(), which falls back to os_chdir(globaldir) when the target buffer has no b_localdir. Solution: Pass kCtxKeepCwd to ctx_switch().
* fix(window): 'winbar' in single-row win overlaps global 'statusline' #41188Barrett Ruth2026-08-07
|
* fix(window): statusline can silently fail to make room #41201Barrett Ruth2026-08-07
|
* feat(cwd)!: :lcd! (bang), rearrange :bcd/:lcd/… scope precedence #41194Justin M. Keyes2026-08-07
| | | | | | | | | | | | | | | | Problem: - buf-local CWD scope is lower priority than :lcd, which is weird. ``` win > buf > tab > global ``` - No way to clear current CWD at a given scope. Solution: - Rerrange scope precedence to: ``` buf > win > tab > global ``` - Introduce "bang" variants (`:bcd!`/`:lcd!`/`:tcd!`) which clears the local CWD for the given scope.
* fix(window): 'laststatus' change pushes win past last row #41189Barrett Ruth2026-08-06
| | | | | | | | | | | | | Problem: Giving a window a status line when `'laststatus'` starts requiring one takes the row from a resizable frame found by walking up the frame tree, but only the window's own leaf frame is grown back. Every frame between the leaf and the donor keeps its old height, so a later resize hands out a row that does not exist and a window's status line ends up on the command line. Solution: Grow the window's frame with `frame_setheight()`, which takes the row from a neighbouring frame and keeps every enclosing frame consistent.
* fix(:bcd): do not "inherit" buffer-local dirJustin M. Keyes2026-08-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Buffer-local CWD (:bcd) is "sticky", similar to window-local CWD (:lcd). But this contradicts one of its main benefits: per-buffer "project root" for LSP, OSC7. Other problems: - A buffer created with :edit/:enew/:new silently inherits b_localdir (and b_prevdir) from the previous buffer. - curbuf_reusable() refuses to recycle a scratch buffer that has `b_localdir`. - After :new/:vnew/:tabnew the CWD sticks to previous buffer's `b_localdir` even though the new curbuf has none, so :new is not equivalent to ":split | enew", and getcwd() disagrees with haslocaldir(). - Requires "which buffer spawned this buffer" semantics that no other buffer-local state has. Solution: Drop sticky/inherit behavior of buffer-local CWD (:bcd). - do_ecmd: always apply the new curbuf's dir (`fix_current_dir`), like `do_autochdir` already does. :tabnew from a :bcd buffer now reverts to global CWD (and fires DirChanged), same as :tabnew from a :lcd window. - curbuf_reusable(): recycling a scratch buffer frees its b_localdir. To get sticky/inherit behavior of CWD, use `:lcd`.
* refactor(editor): cleanup change-directory (:bcd) logicJustin M. Keyes2026-08-04
|
* feat(editor): `:bcd` changes buffer-local directorysaher2026-08-04
| | | | | | | | | | | | | | | | | | Problem: No way to set a buffer-local directory. Use-cases: - "Root dir" for LSP (and the "project" concept). - `:terminal` OSC 7 Solution: Add `:bcd` command. - Extend `getcwd()` to take a third arg; `getcwd(-1, -1, bunfr)` returns the buffer-local working directory. - Buffer-local directories have less priority than window-local ones, and more priority than tab-local ones. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* refactor(window): use window handle in frame layout log (#41153)glepnir2026-08-04
| | | | | Problem: The frame layout debug log uses the obsolete window ID field. Solution: Use the window handle field when printing window information.
* vim-patch:9.2.0881: 'smoothscroll' position is lost when the window height ↵zeertzjq2026-07-31
| | | | | | | | | | | | | | | | changes Problem: With 'smoothscroll' the scroll position of a window is lost when its height changes. Solution: Only reset the skipped columns when 'smoothscroll' is off, where they just serve to keep the cursor visible. closes: vim/vim#20885 https://github.com/vim/vim/commit/17f3923b8c8bacf5785e7721108d39705dc3179c Co-authored-by: Hirohito Higashi <h.east.727@gmail.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* vim-patch:9.2.0871: screen line is lost when splitting a 'winfixheight' ↵zeertzjq2026-07-29
| | | | | | | | | | | | | | | | | | window (#41054) Problem: When the only window has 'winfixheight' set and 'laststatus' is one, splitting it leaves one screen line unused. This happens for example when jumping to an item from a maximized quickfix window (rendcrx) Solution: Do not subtract the height of the status line twice (Hirohito Higashi) fixes: vim/vim#20495 closes: vim/vim#20871 https://github.com/vim/vim/commit/ab36bcc870f47a96c00602bd50bdf1aeb09e71da Co-authored-by: Hirohito Higashi <h.east.727@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* refactor(options): drop OptVal, use ObjectJustin M. Keyes2026-07-29
| | | | | | | | | | | | | Problem: The object subsystem has an intermediate representation for no real reason. Besides the code cost, this also adds an extra (api <=> OptVal) conversion step, which is a (small) perf cost. Solution: We already have `Object`, so use it instead. - drop `OptVal`, `OptValData`, `OptValType`, and related boilerplate. - add `kObjectTypeUnset`.
* refactor(window): extract w_kind for window role #40830glepnir2026-07-20
| | | | | | | | Problem: w_float_is_info conflates a window's role with its floating layout, which are orthogonal properties. Solution: Replace w_float_is_info with a w_kind enum for the window's role.
* fix(window): avoid UAF in `close_windows` (#40853)Barrett Ruth2026-07-20
|
* refactor(globals): group Visual-mode globals in VisualState #40777Justin M. Keyes2026-07-16
|
* fix(window): yeet grid later when closing float in other tabpage #40758Sean Dewar2026-07-15
| | | | | | | Problem: #40731 may still crash if close_buffer autocmds reinsert the float's grid. Plus removing the grid (and posting win_close) is unneeded if win_close_othertab refuses to close the window later, which is possible. Solution: do the stuff before freeing the window, like win_close.
* fix(window): remove float grid from compositor layers before free #40731phanium2026-07-15
| | | | | | | | | Problem: Closing a floating window from a non-current tab frees its grid without removing it from the compositor's `layers` table, so the next `ui_comp_put_grid()` walks a dangling pointer (UAF). Solution: Call `ui_comp_remove_grid()` (and `ui_call_win_close()` for multigrid UIs) before `win_free_mem()`, matching `win_close()` since PR #21551.
* refactor(core): group insert-mode globals in `InsState` #40712Justin M. Keyes2026-07-13
| | | | | | | | | Problem: Insert-mode globals are scattered. Solution: Group them into one struct. Besides improving readability and discoverability, this greatly helps with save/restore of an insert-mode session.
* refactor(insert): rename edit.c => insert.c #40705Justin M. Keyes2026-07-12
| | | | | | | | | | Problem: - `edit.c` is an unnecessarily misleading and less-discoverable name than `insert.c`. - Numerous insert-mode related things are named with a `ins_` prefix. - There is already a `insexpand.c` module... Solution: Rename `edit.c` => `insert.c`.
* refactor(input): rename getchar.c => input.c #40698Justin M. Keyes2026-07-12
| | | | | | | | | | | | Problem: `getchar.c` is a quirky name and doesn't align with our existing `os/input.c` and `tui/input.c` modules, which encompass the same topic at different layers. Solution: Rename `getchar.c` => `input.c` for discoverability. Introduce `dialog.c` for functionality related to showing confirm prompts, dialogs, etc.
* refactor(ctx): drop switch_win/restore_win #40693Justin M. Keyes2026-07-11
|
* fix(winbar): update hidden tabpages on global 'winbar' change #40608Barrett Ruth2026-07-10
| | | | | | | | Problem: Changing global 'winbar' only updates window layout state in the current tabpage. This means existing hidden tabs can keep stale winbar height. Solution: Recompute winbar state for all tabpages on global `'winbar'` changes.
* refactor(ctx): simplify ctx_switch (40674Justin M. Keyes2026-07-10
|
* refactor: unify context-switching conceptsJustin M. Keyes2026-07-10
|
* Merge #40520 nvim_win_resizeJustin M. Keyes2026-07-05
|\
| * feat(api): add nvim_win_resize()XiaowenHu962026-07-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ref #6645 Problem: When a window is resized it takes space from the window right/below first, and only falls back to the window left/above when there is no more room. Sometimes a user wants the space to come from a specific direction. Solution: Add nvim_win_resize(win, width, height, {anchor}) which resizes a window with a choosable anchor edge, letting a window grow leftwards or upwards by taking space from the window to the left or above first. The default anchor reproduces nvim_win_set_width()/nvim_win_set_height().
* | feat(cmdwin): allow tabpage actionsJustin M. Keyes2026-06-29
| |
* | feat(cmdwin): drop CHECK_CMDWINJustin M. Keyes2026-06-29
| | | | | | | | Allow window navigation/creation even while cmdwin is alive! 😱
* | feat(cmdwin): implement cmdwin as a normal buf+winJustin M. Keyes2026-06-25
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: cmdwin (the `:q` cmdline buffer) has various limitations which require special-casing all over the codebase. Besides complicating the code, it also breaks async plugins if they try to create buffers/windows after some work is done, if the user happens to open cmdwin at the wrong the moment: Lua callback: …/guh.nvim/lua/guh/util.lua:531: E11: Invalid in command-line window; <CR> executes, CTRL-C quits stack traceback: [C]: in function 'nvim_buf_delete' …/guh.nvim/lua/guh/util.lua:531: in function <…/guh.nvim/lua/guh/util.lua:526> Solution: Just say no to "inception". Reimplement cmdwin as a normal buffer+window. All of the cmdwin contortions (in both core, and innocent plugins) exist literally only to support "inception": recursive cmdwin-in-cmdline-things, like `<c-r>=`, `/`, search-during-substitute, `:input()`, etc. So we just won't support that (though I have a potential plan for that later, which I call "modal parking lot"). The benefit is that plugins, and core, no longer have to care about cmdwin. BONUS: - mouse-drag on vertical separators works (it only worked for horizontal/statusline before) - inccommand-in-cmdwin now works correctly, for free (thus don't need #40077). POTENTIAL FOLLOWUPS - Drop `CHECK_CMDWIN` ("E11: Invalid in command-line window"), allow chaos. - Unify `BUFLOCK_OK` / `LOCK_OK` ? DESIGN: - Eliminate lots of C globals, `EX_CMDWIN`, etc. - `text_locked()` no longer reports true for cmdwin. - cmdwin = a normal window with 'winfixbuf', 'bufhidden=wipe', 'buftype=nofile'. Invariants come from those options rather than special cases throughout the codebase. - `nv_record` for q:/q//q? calls Lua `nlua_call_vimfn("vim._core.cmdwin", …)`. No `K_CMDWIN` / cmdline-reader detour. - `cedit_key` (`c_CTRL-F`) schedules a deferred event that calls `vim._core.cmdwin.open(type, content, pos)` and returns `Ctrl_C` so the in-flight cmdline cancels. Reader state is not serialized; instead the captured `(type, line, col)` is replayed via `nvim_feedkeys(type..line.."<CR>", "nt", …)` after user confirms. - On confirm/cancel: `<CR>` / `<C-C>` calls into Lua which closes the window and re-feeds the cmdline. BREAKING CHANGES: - Expression-register cmdline (`<C-R>=` from insert-mode) no longer supports cmdwin. Same applies to `input()` / `inputlist()` (already covered by `text_locked`). - Usage of cmdwin in macros/mappings will probably break (assuming they ever worked).
* feat(column): per row click handlers for 'statuscolumn' (#40265)luukvbaal2026-06-20
| | | | | | | | | | | | | | Problem: - Current 'statuscolumn' click label caveat is restrictive. - v:virtnum is not unique to a line if it has both above and below virtual lines. - 'statuscolumn' click handler may expect v:virt/lnum to be set. Solution: - Store per-row click definitions for the statuscolumn in a (nested line/virt number) map. - Implement strategy that gives each 'statuscolumn' row a unique v:virtnum. - Set v:virt/lnum when determining which line is clicked.
* vim-patch:9.0.0927: Coverity warns for using a NULL pointerJan Edmund Lazo2026-06-15
| | | | | | | | | Problem: Coverity warns for using a NULL pointer. Solution: Check for memory allocaion failure. https://github.com/vim/vim/commit/96cbbe29debba25d7eec8d01955c5ac01f5c420d Co-authored-by: Bram Moolenaar <Bram@vim.org>
* vim-patch:9.1.1233: Coverity warns about NULL pointer when triggering WinResizedJan Edmund Lazo2026-06-14
| | | | | | | | | | | | Problem: Coverity warns about NULL pointer when triggering WinResized Solution: Add OOM checks for windows_list like for scroll_dict. Remove void casts that are unnecessary after 9.1.1084 (zeertzjq). closes: vim/vim#16959 https://github.com/vim/vim/commit/b42b9fc41f27f92aaf4f96cd4149f3160e9fe588 Co-authored-by: zeertzjq <zeertzjq@outlook.com>
* vim-patch:9.2.0566: <C-w>f duplicates window if do_ecmd() is aborted (#40061)zeertzjq2026-05-31
| | | | | | | | | | | | | | | | | | | | Problem: If got_int is true when win_close() is called, it unexpectedly fails in the branch that detects failure in apply_autocmds(). This causes wingotofile in do_window() to duplicate current window when do_ecmd() is aborted with got_int. Solution: Fix do_window() to save the got_int value before trying to close the split window (Yohei Kojima). Steps to reproduce: 1. run `touch a && touch .a.swp && echo a > b && vim b` 2. Type `<C-w>f` 3. In the warning dialogue, type `a` to abort 4. Current window is duplicated closes: vim/vim#20382 https://github.com/vim/vim/commit/113e507cdd7be13607db81dcd6cd09aaedf93540 Co-authored-by: Yohei Kojima <yk@y-koj.net>
* fix(autocmd): never show autocommand windows #40032luukvbaal2026-05-30
| | | | | Problem: Redrawing in an autocommand that uses an autocommand window (more common since 5181984d) can result in flickering. Solution: Hide autocommand windows.
* fix(float): simplify :bufdelete focus retry #39928glepnir2026-05-21
| | | | | | | | | | | | Problem: Followup to #39858. close_windows returned a holder window just so do_buffer_ext could retry there, but the non-float branch was dead code and close_windows was called twice. Solution: Check one_window directly in do_buffer_ext, drop the holder, make close_windows void again. Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
* fix(float): :bufdelete in floatwin may change focus #39858glepnir2026-05-21
| | | | | | | | | | Problem: (Followup to 54f22a8f01c0feb27a531b52aedf5cdbd5e51b24.) Deleting another buffer from a floatwin could move focus into the holder window and fire BufEnter for the buffer being deleted. Solution: Use switch_win_noblock() instead of buf_jump_open_win() before recursing into do_buffer_ext().
* feat(api): tab-local option scope #39811Justin M. Keyes2026-05-17
| | | | | | | | | | | | | | | | | | Problem: 2d795face6e4 added support for tab-local options ('cmdheight') to `nvim_get_option_value`, but not to: nvim_get_option_info2() nvim_set_option_value(…, { tab = … }) gettabwinvar() Solution: - Update `options.lua` to model tab-local options. Introduce `kOptScopeTab`. - Handle tab scope in the options layer so it works for all options APIs. Note: - No change to `gettabvar()`. Not sure if needed/wanted. fix https://github.com/neovim/neovim/issues/31140
* feat(events): add TabMoved autocommand event #24137yashlala2026-05-16
| | | | | | | | | | Problem: No way to handle a "tab moved" event. Use-case: tabline plugins may cache tab labels, and need to know when to invalidate their cache. Solution: Add a `TabMoved` event that triggers whenever tabs are reordered via `:tabmove` or via mouse click-and-drag.
* fix(grid): keep grid sizes updated during redraw #39757luukvbaal2026-05-13
| | | | Problem: Assert tripped when window is resized during update_screen(). Solution: Re-allocate grid when resizing happens during update_screen().
* vim-patch:9.2.0445: win_fix_scroll() called before win_comp_pos() in ↵zeertzjq2026-05-06
| | | | | | | | | | | | | | | | | | | | | | | | | | command_height() (#39619) Problem: win_fix_scroll(true) is called before win_comp_pos() in command_height(). Solution: Move win_fix_scroll(true) after win_comp_pos(), matching the ordering used in win_drag_status_line() (Jesse Rosenstock). Patch 9.2.0413 added win_fix_scroll(true) to command_height() to handle splitkeep when cmdheight changes, but placed the call before win_comp_pos(). win_fix_scroll() reads w_winrow to detect window movement (https://github.com/vim/vim/blob/620557bd48865fa3d927901764d2747bf68597b5/src/window.c#L7266), but w_winrow is not recomputed until win_comp_pos() runs (https://github.com/vim/vim/blob/620557bd48865fa3d927901764d2747bf68597b5/src/window.c#L6516). This causes incorrect scroll adjustments and was breaking Test_smoothscroll_incsearch on macOS CI. closes: vim/vim#20138 https://github.com/vim/vim/commit/40fc78f0a185f003844334e7c9dd217d6d993143 Co-authored-by: Gemini Co-authored-by: Jesse Rosenstock <jmr@google.com>
* vim-patch:9.2.0413: Scrolling wrong with 'splitkeep' when changing ↵zeertzjq2026-04-29
| | | | | | | | | | | | | | | 'cmdheight' (#39493) Problem: Cursor is not adjusted when 'cmdheight' is changed to cover the cursor with 'splitkeep' ~= "cursor". Solution: Handle window resize for 'splitkeep' after changing 'cmdheight'. Ensure previous window height is set when changing 'splitkeep' (Luuk van Baal). closes: vim/vim#20043 https://github.com/vim/vim/commit/bd0f3e6da5df70ab2250264d0a7efc7db83c3dc8 Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>