From 03005d0931696bf332c9f06569607798fa64694b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Wed, 3 Jun 2026 11:10:07 +0000 Subject: [PATCH] fix(insert): pumvisible() guard on smart_return/smart_shift_return (audit follow-up) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mappings re-audit confirmed the two new bindings (visual normalize, insert multiline item) are correct — column math matches upstream's s:text_begin, auto-indent handling sound, no parity gaps or regressions. It flagged one low-severity item shared with the pre-existing smart_return: neither guarded the completion popup. Upstream maps / as `pumvisible() ? '' : …`. Added that guard to both smart_return and smart_shift_return (both clients) so a / accepts the completion instead of continuing the list when the popup is open. Left as a documented minor divergence: on an *empty* bullet emits the aligned no-marker continuation rather than upstream's "blank line above, keep marker" (niche). Neovim 305, Vim 299/18/21 pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- autoload/nuwiki/commands.vim | 3 +++ development/vimwiki-gap.md | 10 ++++++++-- lua/nuwiki/commands.lua | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/autoload/nuwiki/commands.vim b/autoload/nuwiki/commands.vim index 2901f4d..823918a 100644 --- a/autoload/nuwiki/commands.vim +++ b/autoload/nuwiki/commands.vim @@ -1268,6 +1268,8 @@ endfunction " returned string is fed into Vim's input stream after the function " finishes, keeping the undo block coherent. function! nuwiki#commands#smart_return() abort + " Accept the completion (plain ) when the popup menu is open, like upstream. + if pumvisible() | return "\" | endif let l:line = getline('.') " `` runs under textlock, so the function must be side-effect- " free on the buffer. Buffer-mutating branches return a `:call @@ -1314,6 +1316,7 @@ endfunction " new marker, indented to align under the item's text — vimwiki's "multiline " list item" (`VimwikiReturn 2 2`). Off a list item it's a plain ``. function! nuwiki#commands#smart_shift_return() abort + if pumvisible() | return "\" | endif let l:line = getline('.') let l:m = matchlist(l:line, '^\(\s*\)\([-*#]\)\s\(.*\)$') if empty(l:m) diff --git a/development/vimwiki-gap.md b/development/vimwiki-gap.md index 2710e33..3d827c6 100644 --- a/development/vimwiki-gap.md +++ b/development/vimwiki-gap.md @@ -581,8 +581,14 @@ fix site. _Fix:_ new `smart_shift_return` (both clients, `` insert mapping): on a list item returns `` + (indent +) `marker-width + 1 (+4 for a checkbox)` spaces — no marker; off a list item, a plain ``. Mirrors `smart_return`'s - auto-indent handling. Covered by `map.insert_shift_cr_multiline` - (`test-keymaps.lua`) + `cr.shift_cr_multiline{,_checkbox}` (`test-keymaps-vim.vim`). + auto-indent handling (column math verified against upstream's `s:text_begin`). + Both `smart_return` and `smart_shift_return` also gained upstream's + `pumvisible()` guard (return a plain `` to accept a completion). _Minor + divergence:_ `` on an *empty* bullet emits the aligned no-marker + continuation rather than upstream's "blank line above, keep the marker" — a + niche case; the common non-empty continuation is exact. Covered by + `map.insert_shift_cr_multiline` (`test-keymaps.lua`) + + `cr.shift_cr_multiline{,_checkbox}` (`test-keymaps-vim.vim`). - [x] **`gLH` / `gLL` / `gLR`** _(fixed 2026-06-03)_ — upstream binds these as case-variant **aliases** of `gLh` / `gLl` / `gLr` (dedent / indent whole item, renumber all lists; upstream `ftplugin/vimwiki.vim:553,555,561`). nuwiki had diff --git a/lua/nuwiki/commands.lua b/lua/nuwiki/commands.lua index 0e06249..b48c631 100644 --- a/lua/nuwiki/commands.lua +++ b/lua/nuwiki/commands.lua @@ -963,6 +963,9 @@ function M.smart_return() local cr = tc('') local esc = tc('') + -- Accept the completion (plain ) when the popup menu is open, like upstream. + if vim.fn.pumvisible() == 1 then return cr end + if is_table_row(line) then local row = vim.api.nvim_win_get_cursor(0)[1] return string.format( @@ -1006,6 +1009,7 @@ end function M.smart_shift_return() local line = vim.api.nvim_get_current_line() local cr = vim.api.nvim_replace_termcodes('', true, false, true) + if vim.fn.pumvisible() == 1 then return cr end local indent, marker, after = line:match('^(%s*)([%-%*%#])%s(.*)$') if not marker then local n