parity(5): smart <CR> in insert mode (VimwikiReturn)
Bind `<CR>` in insert mode as an `<expr>` map to a `smart_return`
helper. Behaviour matches upstream vimwiki's `:VimwikiReturn`:
- On a list line with content → continue the list with the same
marker on a new line (preserving leading checkbox `[ ]` if any).
- On an empty list line (marker only) → clear the marker and break
out of the list with a plain newline.
- Inside a `|…|` table row → insert a fresh empty row below with
the same column count, cursor lands inside the first cell.
- Otherwise → plain `<CR>`.
Implementation note: the helper is `<expr>`-bound, which means
textlock is active and the buffer can't be mutated from inside the
callback. The function returns key sequences only — including
`<Esc>0DA<CR>` for the empty-list break and `<Esc>0li` for the
table-row cursor jump — so every effect flows through Vim's normal
keystroke pipeline and stays undo-coherent.
Both Lua and VimL counterparts shipped.
Tests: 4 new in scripts/test-keymaps.lua covering list continuation,
checkbox preservation, empty-marker break-out, and new table row.
Gates: 421 Rust / 35 Neovim / 12 Vim.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -254,6 +254,11 @@ function M.attach(bufnr, mappings)
|
||||
{ desc = 'nuwiki: cycle list symbol backward (insert)' }, bufnr)
|
||||
map('i', '<C-L><C-M>', cmd.list_toggle_or_add_checkbox,
|
||||
{ desc = 'nuwiki: toggle/add checkbox (insert)' }, bufnr)
|
||||
|
||||
-- Smart <CR>: continue list / table rows. `<expr>` so the function
|
||||
-- result is the keystrokes fed — keeps undo coherent.
|
||||
map('i', '<CR>', cmd.smart_return,
|
||||
{ desc = 'nuwiki: smart return (insert)', expr = true }, bufnr)
|
||||
end
|
||||
|
||||
-- ===== Header levels + nav =====
|
||||
|
||||
Reference in New Issue
Block a user