parity(3): text objects — aH/iH, al/il, a\/i\, ac/ic

Five operator-pending + visual text-object pairs, matching upstream
vimwiki:

  ah / ih   heading section only (stops at any next heading)
  aH / iH   heading section + sub-tree (stops at same-or-shallower)
  al / il   list item (line, with / without marker prefix + checkbox)
  a\ / i\   table cell (with / without surrounding `|` separators)
  ac / ic   table column (with / without the header separator row)

Pre-existing `ah` used aH semantics — fixed to match vimwiki: `ah`
now stops at the next heading regardless of level. `aH` is the new
descendants-inclusive variant.

Implementation notes:
- Pure regex; no LSP round-trip. Each helper computes a `(line, col)`
  rectangle and drives the selection with feedkeys.
- Operator-pending and visual need different feed sequences. In visual
  the previous anchor is sticky, so bounce through `<Esc>` first. In
  operator-pending an `<Esc>` would CANCEL the pending operator —
  feed the visual keys directly so Vim treats them as the motion.
- Re-exported helpers (`_heading_block`, `_cell_ranges`,
  `_current_cell_for_line`, `_table_bounds`) keep the integration
  surface testable without going through Vim's visual-mode pipeline,
  whose `'<`/`'>` mark semantics fight headless test harnesses.

Tests: 6 new in scripts/test-keymaps.lua — five pure-helper cases
plus one end-to-end `dah` deletion to verify the operator-pending
wiring.

Gates: 421 Rust / 31 Neovim / 12 Vim.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 21:23:44 +00:00
parent 46ae618b5f
commit fd4d902fde
2 changed files with 296 additions and 24 deletions
+67
View File
@@ -334,6 +334,73 @@ vim.defer_fn(function()
wait_ms = 1500,
})
-- ===== Text objects (Cluster 3) =====
-- Exercise the pure helpers directly (cell ranges, heading block,
-- table bounds). The visual-mode integration is verified in a single
-- end-to-end case via mark inspection, which exercises the full
-- operator-pending path.
local function tobj_case(name, fn)
local ok, err = pcall(fn)
record(ok, name, ok and '' or tostring(err))
end
tobj_case('textobj.heading_block_section_only', function()
set_buf({ '= h1 =', 'a', '== h2 ==', 'b', '== h3 ==', 'c' })
local s, e = require('nuwiki.textobjects')._heading_block(1, false)
if not (s == 1 and e == 2) then
error(string.format('section_only: got (%s,%s) want (1,2)', s, e))
end
end)
tobj_case('textobj.heading_block_subtree', function()
set_buf({ '= h1 =', 'a', '== h2 ==', 'b', '== h3 ==', 'c' })
local s, e = require('nuwiki.textobjects')._heading_block(1, true)
if not (s == 1 and e == 6) then
error(string.format('subtree: got (%s,%s) want (1,6)', s, e))
end
end)
tobj_case('textobj.cell_ranges_three_cells', function()
local r = require('nuwiki.textobjects')._cell_ranges('| a | b | c |')
if #r ~= 3 then error('want 3 cells, got ' .. #r) end
-- Inside each cell, content includes the surrounding spaces.
if not (r[1][1] == 2 and r[2][1] > r[1][2] and r[3][1] > r[2][2]) then
error('cell ordering broken: ' .. vim.inspect(r))
end
end)
tobj_case('textobj.current_cell_picks_middle', function()
-- `| a | b | c |` cursor on the `b` (1-based col 8).
local idx = require('nuwiki.textobjects')._current_cell_for_line(
'| a | b | c |', 8)
if idx ~= 2 then error('expected cell 2, got ' .. tostring(idx)) end
end)
tobj_case('textobj.table_bounds_walks_contig_block', function()
set_buf({ 'before', '| a | b |', '| c | d |', '', 'after' })
vim.api.nvim_win_set_cursor(0, { 2, 0 })
local s, e = require('nuwiki.textobjects')._table_bounds(2)
if not (s == 2 and e == 3) then
error(string.format('want (2,3) got (%s,%s)', s, e))
end
end)
-- One end-to-end: operator-pending `dah` should delete the heading
-- section. This avoids the visual-mode `'<`/`'>` mark dance and
-- relies on Vim's actual operator pipeline to verify the keymap is
-- correctly wired into `omap`.
tobj_case('textobj.dah_deletes_heading_section', function()
set_buf({ '= h1 =', 'body', '= h2 =', 'rest' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
send('dah')
sleep(100)
local got = get_lines()
-- After deleting heading section (lines 1-2), buffer should be the
-- remaining two lines. There may be a trailing empty line depending
-- on linewise delete semantics; allow both shapes.
if not (vim.deep_equal(got, { '= h2 =', 'rest' })
or vim.deep_equal(got, { '', '= h2 =', 'rest' })) then
error('dah result: ' .. vim.inspect(got))
end
end)
-- ===== Diary nav =====
-- Tested via the LSP open-* responses; can't fully validate without
-- a populated diary, but at least confirm the maps fire without