aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/win_config.c
Commit message (Collapse)AuthorAge
* fix(setreg): use better estimate of register widthbfredl8 days
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | vim-patch:9.2.1175: setreg() block width wrong for unprintable chars When yanking, the width of a <c-v>{motion}y register is determined by the virtual colums of the text. However in setreg() in 'b' mode use an idosyncratic width measurement where C0 control chars (ASCII 0x00 - 0x19) and invalid UTF-8 bytes have width 1 instead of their display width (2 or 4 cells). Consider the following test case: let strings = ['"reference', '"Übel', "\"aa\x07bb", "\"qq\x82", "\"x\nbabbel"] for string in strings call append('$', string) exec "normal G0\<c-v>$\"ay" let one = getregtype('a') if string != strings[-1] call setreg("b", string, 'b') let two = getregtype('b') else let two = "na" endif call setreg("c", [string], 'b') let three = getregtype('c') call append('$', '"yank: '.one.", string: ".two.", list: ".three) endfor AFter this fix, all the three ways of measuring the width gives equal values (or two, in the case of not being able to use setreg() with a plain string in the first case)
* refactor(mbyte): use StrCharInfo/ClusterInfo also for str[len] casesbfredl14 days
| | | | | | | | part of a series, next big one is gonna be bring utf_ptr2schar and friends into the New world. after that it might be worth brushing of some benchmarks and re-microoptimize the hottest loops. also some const-y constess but it is fine.
* 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.
* docs: misc, :bcd, slug()Justin M. Keyes2026-08-06
|
* feat(float): 'previewpopup' option #26799glepnir2026-07-23
| | | | | | | | Problem: The preview-window (:pedit, etc.) always uses a split, but it would be useful as a floatwin (or "popup"). Solution: Support Vim's 'previewpopup' option.
* docs: misc, remove some old help tags #40214Justin M. Keyes2026-07-18
| | | | | | | | | | - Remove old help tags: they add noise to cmdline completion. Co-authored-by: acehinnnqru <acehinnnqru@gmail.com> Co-authored-by: KangaZero <samuelyongw@gmail.com> Co-authored-by: Simone Ragusa <hi@interrato.dev> Co-authored-by: Chinmay Dalal <~chinmay/public-inbox@lists.sr.ht> Co-authored-by: coyaSONG <66289470+coyaSONG@users.noreply.github.com> Co-authored-by: Olivia Kinnear <git@superatomic.dev>
* refactor(ctx): drop switch_win/restore_win #40693Justin M. Keyes2026-07-11
|
* 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): 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).
* fix(option): allow empty/blank edges in 'winborder' #40112glepnir2026-06-05
| | | | | | | | | | Problem: The comma form of 'winborder' is split with copy_option_part(), whose skip_to_option_part() eats spaces after a comma, and empty fields are rejected. Solution: Split the comma form literally on ',', keeping empty fields and single-space fields.
* Merge #40057 from luukvbaal/hidenodrawJustin M. Keyes2026-06-02
|\ | | | | perf(redraw): don't redraw hidden windows
| * fix(float): validate conflicts for nvim_win_set_config()Luuk van Baal2026-06-01
| | | | | | | | | | | | | | | | Problem: nvim_win_set_config() does not error on flags not allowed for non-floating windows. `hide` should not be allowed for non-floating windows. Solution: Check that a window is a split when reconfiguring. Error when trying to hide a split window.
| * perf(redraw): don't redraw hidden windowsLuuk van Baal2026-05-31
| | | | | | | | | | Problem: Hidden windows are redrawn unnecessarily. Solution: If a window is hidden, don't bother drawing it.
* | fix(float): title/footer shows printable control chars #40047glepnir2026-05-30
|/ | | | | | | | | | Problem: Literal tab (or other control char) in a float title/footer is not made printable, so it renders incorrectly instead of as "^I". Solution: Normalize title/footer text for display like 'statusline' tab to "^I", parameterize parse_virt_text() with untab and recompute the width.
* docs: misc, options, pos/rangeJustin M. Keyes2026-05-30
|
* docs: misc #39045Justin M. Keyes2026-04-18
|
* refactor(api): rename "window" to "win" (positional parameters) #39083Justin M. Keyes2026-04-15
| | | | | | | continues d0af4cd9094f. This commit renames positional parameters. This is only "cosmetic", but is intended to make it extra clear which name is preferred, since people often copy existing code despite the guidelines in `:help dev-naming`.
* refactor(api): rename buffer to buf (positional parameters) #39013Justin M. Keyes2026-04-15
| | | | | | | | In 3a4a66017b74, 4d3a67cd6201, df8d98173cbc we renamed "buffer" to "buf" in dict parameters and return-values. This commit renames positional parameters. This is only "cosmetic", but is intended to make it extra clear which name is preferred, since people often copy existing code despite the guidelines in `:help dev-naming`.
* feat(api): use zindex to determine dimmed cursor shape #39054luukvbaal2026-04-14
| | | | | | | | | | | Problem: The cursor shape is changed to indicate when it is behind an unfocused floating window (since a2b92a5e). This behavior cannot be controlled by a floating window that doesn't want to dim the cursor. Solution: Assign a zindex-offset of 50 to the zindex of the current window. To not dim the cursor when creating a floating window on top of the current window one can assign the zindex accordingly.
* fix(api): use standard error messagesJustin M. Keyes2026-03-16
|
* docs: miscJustin M. Keyes2026-03-16
|
* fix(api): improve external window validationSean Dewar2026-03-14
| | | | | | | | | | | | | | | | | Problem: "win" is allowed in external window configs in some cases. External window converted to normal float can't move tabpages in one nvim_win_set_config call. External window can't be turned into a normal split. Solution: disallow setting "win" for external windows. Allow external window to move tabpages, which turns it non-external. Allow external window to be turned into a (non-external) split. parse_win_config has more validation issues from not considering the window's existing config enough (not from this PR). For example, zindex can be set for an existing split if "split"/"vertical" isn't given, despite intending for that to be an error. Plus the logic is confusing. It could do with a refactor at some point...
* fix(api): disallow moving window between tabpages in more casesSean Dewar2026-03-14
| | | | | | | | | | | | | | | | Problem: more cases where it may not be safe to move a window between tabpages. Solution: check them. Rather speculative... I haven't spend much time looking, but I didn't find existing code that sets these locks to skip checking win_valid. (what I did find called it anyway, like in win_close) Still, I think it's a good precaution for what future code might do. If the fact that nvim_win_set_config *actually* moves windows between tabpages causes unforeseen issues, "faking" it like ":wincmd T" may be an alternative: split a new window, close the old one, but instead also block autocmds, copy the old window's config, and give it its handle?
* feat(api): nvim_win_set_config can move split to other tp as floatwinSean Dewar2026-03-14
| | | | | | | Problem: not possible for nvim_win_set_config to convert a split to a floatwin, then move it to another tabpage in one call. Solution: allow it.
* fix(api): relax config validation for "win"Sean Dewar2026-03-14
| | | | | | | | | | | | | | | | Problem: only possible to move floats between tabpages if relative=win, which has the restrictive effect of also anchoring it to the target window. Solution: allow "win" without "relative" or "split"/"vertical". Only assume missing "win" is 0 if relative=win is given to maintain that behaviour. (or when configuring a new window) Also add an error when attempting to change a split into a float that's in another tabpage, as this isn't actually supported yet. (until the next commit) Maybe this could do with some bikeshedding. Unclear if "win" should require "relative" to be given, like with "row"/"col"; this can be annoying though as specifying "relative" requires other fields to be given too.
* refactor(window): lastwin_nofloating takes tpSean Dewar2026-03-14
|
* fix(api): don't config split as floatwin relative to itselfSean Dewar2026-03-14
| | | | | | | | | | Problem: possible to configure a split as a floatwin with relative=win that is relative to itself. Solution: fix the check. Not caused by this PR; just something I noticed when about to fix the validation logic.
* fix(api): win_config_float_tp grid removal, redrawSean Dewar2026-03-14
| | | | | | | | | | | | | | | | | | | | | | | | Problem: when nvim_win_set_config moves a floatwin between tabpages, its grid may remain if temporarily inside another tabpage. Also, things like tablines aren't redrawn. Solution: always remove its grid. Set must_redraw so things are redrawn even if w_redr_type was already set for the old tabpage. I don't think it's necessary to do anything extra here when removing the grid: - win_ui_flush calls ui_call_win_hide anyway, and calling it manually ends up sending two win_hide events. - ui_comp_remove_grid safely does nothing if the grid doesn't exist. - w_pos_changed is set by win_config_float later, if that's needed. I think the pending_comp_index_update set by ui_comp_remove_grid is enough anyway, at least for making sure win_ui_flush sends win_hide. Added test fails with the prior approach of checking `parent_tp != curtab`, but also `win_tp == curtab`. (which is a better, but still flawed alternative) The added redrawing here also supersedes setting w_hl_needs_update, and also redraws stuff like the tabline to pass the new test.
* refactor(api): cleanup, more comments, more tests, newsSean Dewar2026-03-14
| | | | | | | | | - Factor out logic to keep nvim_win_set_config clean. - Clean up a few things, remove redundant logic, reflow some lines. - Add some more comments where appropriate. - Don't consider negative "win", as that's only relevant for splits. - Add more test coverage. - Add news.txt entry.
* feat(api): nvim_win_set_config can move floatwin to another tabpageglepnir2026-03-14
| | | | | | | | Problem: nvim_win_set_config can't move floating windows to different tab pages. Solution: allow it. Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
* docs: api, messages, lsp, trustJustin M. Keyes2026-03-11
| | | | | gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
* Merge #38206 nvim_win_set_configJustin M. Keyes2026-03-09
|\
| * fix(api): unnecessary errors when not moving splitSean Dewar2026-03-09
| | | | | | | | | | | | | | Problem: nvim_win_set_config may raise unnecessary errors when not moving a split. Solution: skip checks related to moving when only maybe resizing a split.
| * fix(api): redraw after setting minimal styleSean Dewar2026-03-09
| | | | | | | | | | | | | | | | Problem: No explicit redraw after setting style=minimal in nvim_open_win or nvim_win_set_config, which may cause it to appear like it's not set. Solution: call changed_window_setting after applying the style, which should be enough for these options.
* | fix(api): don't re-apply minimal style if unchanged #38152Sean Dewar2026-03-09
|/ | | | | | | | | | Problem: nvim_win_set_config with style=minimal re-applies option values even if the new style is unchanged from the old. This may be undesirable after #38122. Solution: don't bother in this case. See https://github.com/neovim/neovim/pull/38122#issuecomment-3996994189. A reversal of https://github.com/neovim/neovim/pull/22865#discussion_r1161598973 so its associated test has been updated.
* fix(api): merge split window config only on successSean Dewar2026-03-08
| | | | | | | | | | | | | | | Problem: nvim_win_set_config may merge configs despite failing to configure a split, and without applying necessary side-effects (like setting style=minimal options). Plus, autocommands may apply a different config after the merge, causing side-effects to apply for an outdated config. Solution: merge configs last, only on success. Include fields only relevant to splits. Properly set _cmdline_offset for splits. Maybe better to disallow _cmdline_offset for splits instead, as the pum is relative to cmdline_row anyway? (I didn't want to change behaviour too much) Also use expect_unchanged in an unrelated test to quash a warning.
* refactor(api): move split handling logic outSean Dewar2026-03-08
| | | | It was getting unwieldy.
* fix(api): style=minimal not applied immediately for unmoved splitSean Dewar2026-03-08
| | | | | | | | | Problem: nvim_win_set_config with style="minimal" does not take immediate effect when a split is not moved. Solution: don't skip nvim_win_set_config's epilogue when only a resize may be needed. De-duplicate resize logic and remove unnecessary redraw. (win_set*_win already handles that)
* fix(api): return "style" in nvim_win_get_config() #38122Sean Dewar2026-03-03
| | | | | | | | | | Problem: nvim_win_get_config() does not return a window's "style". Solution: always include it, and document `style=""`. Always included so it can be used reciprocally with nvim_open_win() or nvim_win_set_config(). (otherwise the config of a window with kWinStyleUnused will not unset the kWinStyleMinimal style of another window if passed to nvim_win_set_config, for example)
* docs(api): nvim_open_win "split" with negative "win" #38032Sean Dewar2026-02-23
| | | Acts like :topleft/botright.
* fix(api): open_win leak from naughty autocommandsSean Dewar2025-12-21
| | | | | | | | Problem: error set by win_set_buf may leak if autocommands immediately close the new window. Solution: free the error set by win_set_buf. (prefer nvim_open_win's error as it's more important and will cause 0 to be returned)
* fix(api): ignore split_disallowed when opening a floatSean Dewar2025-12-21
| | | | | | | | | | | | | | | | | Problem: split_disallowed seemingly exists to prevent issues from changing frames to accomodate a split window, which doesn't apply to floats. Solution: remove the restriction for nvim_open_win, but only for floats. (continue to check b_locked_split though) NOTE: like before, the buffer we check b_locked_split for may not actually be the target buffer "buf", as the later call to win_set_buf can fail to switch to "buf" due to autocommands. (among other things) Maybe we could attempt to close the new window in that case (or switch to a different buffer if that also fails), but this is safer. (and simpler) Fixes #36857 (and possibly some spurious E242s I've observed from extui)
* docs: miscJustin M. Keyes2025-12-06
| | | | | | fix https://github.com/neovim/neovim.github.io/issues/419 Co-authored-by: Rob Pilling <robpilling@gmail.com>
* feat(float): 'statusline' in floating windows #36521glepnir2025-11-26
| | | | | | | Problem: Can't show 'statusline' in floating windows. Solution: Use window-local 'statusline' to control floating window statusline visibility.
* docs: misc, build, lspJustin M. Keyes2025-11-22
|
* feat(api): nvim_win_set_config accepts unchanged "noautocmd" #36463glepnir2025-11-18
| | | | | | Problem: Cannot reuse same config with noautocmd for both window creation and updates, even when value is unchanged. Solution: Only reject noautocmd changes for existing windows.
* fix(ui): 'pumborder' parsing, shadow #36127glepnir2025-10-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: 1. Setting `pumborder=+,+,+,+,+,+,+,+` failed to render the custom border characters correctly. The issue occurred in `parse_winborder()` where it incorrectly used `p_winborder` instead of the `border_opt` parameter when the option value didn't contain commas. 2. In `pum_redraw()`, calling `parse_border_style()` directly with the option string failed to parse comma-separated border characters. 3. Missing documentation for PmenuShadow and PmenuShadowThrough highlight groups used by the shadow border style. 4. Coverity reports CID 631420: passing WinConfig (480 bytes) by value in `grid_draw_border()`. 5. crash when using `shadow` value on pumborder. Solution: 1. Fix `parse_winborder()` to use `border_opt` parameter consistently, ensuring the correct option value is parsed regardless of which option (winborder/pumborder) is being set. 2. Update `pum_redraw()` to call `parse_winborder()` instead of `parse_border_style()`, properly handling both predefined styles and custom comma-separated border characters. 3. Add documentation for PmenuShadow (blended shadow areas) and PmenuShadowThrough (see-through corners) highlight groups. 4. Change `grid_draw_border()` to accept WinConfig by pointer. 5. When the "shadow" style is used, no additional row and column offset is applied, and the border width is reduced.
* feat(ui): 'pumborder' (popup menu border) #25541glepnir2025-10-10
| | | | | | | | | Problem: Popup menu cannot have a border. Solution: Support 'pumborder' option. Generalize `win_redr_border` to `grid_redr_border`, which redraws border for window grid and pum grid.