parity(6): insert-mode <Tab>/<S-Tab> table cell nav

`<Tab>` / `<S-Tab>` in insert mode navigate between table cells when
the cursor is on a `|…|` row, otherwise they pass through to their
default insert-mode behaviour (literal tab / shift-tab). Same
`<expr>`-mapping idiom as Cluster 5's smart_return.

  <Tab>    next cell; creates a fresh row below if past the last cell
  <S-Tab>  previous cell; no-op past the first

Cursor lands immediately after the destination cell's leading `|`,
matching upstream vimwiki's `vimwiki#tbl#go_*_cell` behaviour.

Both Lua and VimL counterparts wired into ftplugin's existing
table_editing block (gated alongside `gqq`/`<A-Left>`).

Tests: 4 new in scripts/test-keymaps.lua — next cell, new-row
overflow, previous cell, and pass-through outside a table.

Gates: 421 Rust / 39 Neovim / 12 Vim.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 21:37:53 +00:00
parent e347f605ff
commit 2562a046db
5 changed files with 172 additions and 0 deletions
+58
View File
@@ -726,6 +726,64 @@ function! nuwiki#commands#smart_return() abort
return "\<CR>"
endfunction
" Insert-mode `<Tab>` / `<S-Tab>` table navigation — vimwiki parity.
" Used as `<expr>` mappings so we can pass `<Tab>` / `<S-Tab>` through
" verbatim when the cursor isn't on a table row.
function! s:table_cell_starts(line) abort
let l:out = []
let l:pos = 0
while 1
let l:bar = stridx(a:line, '|', l:pos)
if l:bar < 0 | break | endif
call add(l:out, l:bar + 1)
let l:pos = l:bar + 1
endwhile
return l:out
endfunction
function! nuwiki#commands#smart_tab() abort
let l:line = getline('.')
if l:line !~# '^\s*|.*|\s*$'
return "\<Tab>"
endif
let l:starts = s:table_cell_starts(l:line)
if len(l:starts) < 2
return "\<Tab>"
endif
let l:col = col('.') - 1
for l:s in l:starts
if l:s > l:col + 1 && l:s < len(l:line)
return "\<Esc>" . (l:s + 1) . '|i'
endif
endfor
let l:n = len(l:starts) - 1
let l:new_row = '|' . repeat(' |', l:n)
return "\<CR>" . l:new_row . "\<Esc>0li"
endfunction
function! nuwiki#commands#smart_shift_tab() abort
let l:line = getline('.')
if l:line !~# '^\s*|.*|\s*$'
return "\<S-Tab>"
endif
let l:starts = s:table_cell_starts(l:line)
if len(l:starts) < 2
return "\<S-Tab>"
endif
let l:col = col('.') - 1
let l:current_idx = -1
let l:i = 0
for l:s in l:starts
if l:s <= l:col + 1 | let l:current_idx = l:i | endif
let l:i += 1
endfor
if l:current_idx <= 0
return "\<S-Tab>"
endif
let l:target = l:starts[l:current_idx - 1]
return "\<Esc>" . (l:target + 1) . '|i'
endfunction
" `:VimwikiNormalizeLink` — wrap the word at cursor as `[[word]]`
" without following. Pure-VimL.
function! nuwiki#commands#normalize_link() abort