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:
2026-05-12 21:34:36 +00:00
parent fd4d902fde
commit e347f605ff
5 changed files with 125 additions and 0 deletions
+32
View File
@@ -401,6 +401,38 @@ vim.defer_fn(function()
end
end)
-- ===== Smart <CR> (Cluster 5) =====
run('cr.continues_list_marker', {
lines = { '- first' },
cursor = { 1, 7 }, -- end of line
keys = 'A<CR>second<Esc>',
expect_lines = { '- first', '- second' },
wait_ms = 100,
})
run('cr.continues_checkbox', {
lines = { '- [ ] first' },
cursor = { 1, 11 },
keys = 'A<CR>second<Esc>',
expect_lines = { '- [ ] first', '- [ ] second' },
wait_ms = 100,
})
run('cr.breaks_on_empty_list_line', {
lines = { '- ' },
cursor = { 1, 2 },
keys = 'A<CR>plain<Esc>',
expect_lines = { '', 'plain' },
wait_ms = 100,
})
run('cr.adds_new_table_row', {
lines = { '| a | b |' },
cursor = { 1, 4 }, -- inside `a`
keys = 'A<CR>x<Esc>',
-- New row inserted below with empty cells; cursor jumps to first.
expect_lines = { '| a | b |', '|x | |' },
wait_ms = 100,
})
-- ===== Diary nav =====
-- Tested via the LSP open-* responses; can't fully validate without
-- a populated diary, but at least confirm the maps fire without