fix(insert): pumvisible() guard on smart_return/smart_shift_return (audit follow-up)
The mappings re-audit confirmed the two new bindings (visual <CR> normalize, insert <S-CR> 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 <CR>/<S-CR> as `pumvisible() ? '<CR>' : …`. Added that guard to both smart_return and smart_shift_return (both clients) so a <CR>/<S-CR> accepts the completion instead of continuing the list when the popup is open. Left as a documented minor divergence: <S-CR> 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) <noreply@anthropic.com>
This commit is contained in:
@@ -1268,6 +1268,8 @@ endfunction
|
|||||||
" returned string is fed into Vim's input stream after the function
|
" returned string is fed into Vim's input stream after the function
|
||||||
" finishes, keeping the undo block coherent.
|
" finishes, keeping the undo block coherent.
|
||||||
function! nuwiki#commands#smart_return() abort
|
function! nuwiki#commands#smart_return() abort
|
||||||
|
" Accept the completion (plain <CR>) when the popup menu is open, like upstream.
|
||||||
|
if pumvisible() | return "\<CR>" | endif
|
||||||
let l:line = getline('.')
|
let l:line = getline('.')
|
||||||
" `<expr>` runs under textlock, so the function must be side-effect-
|
" `<expr>` runs under textlock, so the function must be side-effect-
|
||||||
" free on the buffer. Buffer-mutating branches return a `<Cmd>:call
|
" free on the buffer. Buffer-mutating branches return a `<Cmd>:call
|
||||||
@@ -1314,6 +1316,7 @@ endfunction
|
|||||||
" new marker, indented to align under the item's text — vimwiki's "multiline
|
" 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 `<CR>`.
|
" list item" (`VimwikiReturn 2 2`). Off a list item it's a plain `<CR>`.
|
||||||
function! nuwiki#commands#smart_shift_return() abort
|
function! nuwiki#commands#smart_shift_return() abort
|
||||||
|
if pumvisible() | return "\<CR>" | endif
|
||||||
let l:line = getline('.')
|
let l:line = getline('.')
|
||||||
let l:m = matchlist(l:line, '^\(\s*\)\([-*#]\)\s\(.*\)$')
|
let l:m = matchlist(l:line, '^\(\s*\)\([-*#]\)\s\(.*\)$')
|
||||||
if empty(l:m)
|
if empty(l:m)
|
||||||
|
|||||||
@@ -581,8 +581,14 @@ fix site.
|
|||||||
_Fix:_ new `smart_shift_return` (both clients, `<expr>` insert mapping): on a
|
_Fix:_ new `smart_shift_return` (both clients, `<expr>` insert mapping): on a
|
||||||
list item returns `<CR>` + (indent +) `marker-width + 1 (+4 for a checkbox)`
|
list item returns `<CR>` + (indent +) `marker-width + 1 (+4 for a checkbox)`
|
||||||
spaces — no marker; off a list item, a plain `<CR>`. Mirrors `smart_return`'s
|
spaces — no marker; off a list item, a plain `<CR>`. Mirrors `smart_return`'s
|
||||||
auto-indent handling. Covered by `map.insert_shift_cr_multiline`
|
auto-indent handling (column math verified against upstream's `s:text_begin`).
|
||||||
(`test-keymaps.lua`) + `cr.shift_cr_multiline{,_checkbox}` (`test-keymaps-vim.vim`).
|
Both `smart_return` and `smart_shift_return` also gained upstream's
|
||||||
|
`pumvisible()` guard (return a plain `<CR>` to accept a completion). _Minor
|
||||||
|
divergence:_ `<S-CR>` 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
|
- [x] **`gLH` / `gLL` / `gLR`** _(fixed 2026-06-03)_ — upstream binds these as
|
||||||
case-variant **aliases** of `gLh` / `gLl` / `gLr` (dedent / indent whole item,
|
case-variant **aliases** of `gLh` / `gLl` / `gLr` (dedent / indent whole item,
|
||||||
renumber all lists; upstream `ftplugin/vimwiki.vim:553,555,561`). nuwiki had
|
renumber all lists; upstream `ftplugin/vimwiki.vim:553,555,561`). nuwiki had
|
||||||
|
|||||||
@@ -963,6 +963,9 @@ function M.smart_return()
|
|||||||
local cr = tc('<CR>')
|
local cr = tc('<CR>')
|
||||||
local esc = tc('<Esc>')
|
local esc = tc('<Esc>')
|
||||||
|
|
||||||
|
-- Accept the completion (plain <CR>) when the popup menu is open, like upstream.
|
||||||
|
if vim.fn.pumvisible() == 1 then return cr end
|
||||||
|
|
||||||
if is_table_row(line) then
|
if is_table_row(line) then
|
||||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
return string.format(
|
return string.format(
|
||||||
@@ -1006,6 +1009,7 @@ end
|
|||||||
function M.smart_shift_return()
|
function M.smart_shift_return()
|
||||||
local line = vim.api.nvim_get_current_line()
|
local line = vim.api.nvim_get_current_line()
|
||||||
local cr = vim.api.nvim_replace_termcodes('<CR>', true, false, true)
|
local cr = vim.api.nvim_replace_termcodes('<CR>', true, false, true)
|
||||||
|
if vim.fn.pumvisible() == 1 then return cr end
|
||||||
local indent, marker, after = line:match('^(%s*)([%-%*%#])%s(.*)$')
|
local indent, marker, after = line:match('^(%s*)([%-%*%#])%s(.*)$')
|
||||||
if not marker then
|
if not marker then
|
||||||
local n
|
local n
|
||||||
|
|||||||
Reference in New Issue
Block a user