fix(tables): cycle Tab into the next row instead of inserting one
Pressing <Tab> past the last cell unconditionally appended a new row below, even when there was already a next row to jump into. Tabbing through a header → separator → body table from the header row inserted a blank row between header and separator instead of landing in the first body cell. After the final cell, walk forward from the current row to the end of the table, skip any separator row, and jump to the first cell of the next data row. Only insert a fresh row when the cursor is on the table's last row (or only separator rows follow). Applied to both the Vim (autoload/nuwiki/commands.vim) and Neovim (lua/nuwiki/ commands.lua) sides so the two harnesses stay in sync; covered by new keymap tests in scripts/test-keymaps-vim.vim and test-keymaps.lua. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1025,10 +1025,22 @@ function! nuwiki#commands#smart_tab() abort
|
||||
if l:target_idx < len(l:starts)
|
||||
return "\<Cmd>call nuwiki#commands#_table_jump_to_cell(" . line('.') . ", " . l:target_idx . ")\<CR>"
|
||||
endif
|
||||
" Past the final cell → add a fresh row below, cursor in its first cell.
|
||||
" Past the final cell. Prefer cycling into the next existing row (skipping
|
||||
" any separator row); only insert a fresh row when we're already on the
|
||||
" table's last row.
|
||||
let l:row = line('.')
|
||||
let [l:s_row, l:e_row] = s:find_table_range(l:row)
|
||||
let l:next = l:row + 1
|
||||
while l:next <= l:e_row
|
||||
let [l:_, l:next_cells] = s:parse_table_row(getline(l:next))
|
||||
if !s:is_sep_row(l:next_cells)
|
||||
return "\<Cmd>call nuwiki#commands#_table_jump_to_cell(" . l:next . ", 1)\<CR>"
|
||||
endif
|
||||
let l:next += 1
|
||||
endwhile
|
||||
let l:indent = matchstr(l:line, '^\s*')
|
||||
let l:cursor_col = len(l:indent) + 2
|
||||
return "\<Cmd>call nuwiki#commands#_table_insert_row_below(" . line('.') . ", " . l:cursor_col . ")\<CR>"
|
||||
return "\<Cmd>call nuwiki#commands#_table_insert_row_below(" . l:row . ", " . l:cursor_col . ")\<CR>"
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#smart_shift_tab() abort
|
||||
|
||||
Reference in New Issue
Block a user