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:
+22
-6
@@ -826,16 +826,32 @@ function M.smart_tab()
|
||||
if start <= col + 1 then current_idx = i end
|
||||
end
|
||||
local target_idx = current_idx + 1
|
||||
if target_idx >= #cell_starts then
|
||||
if target_idx < #cell_starts then
|
||||
return string.format(
|
||||
'<Cmd>lua require("nuwiki.commands")._table_insert_row_below(%d)<CR>',
|
||||
row
|
||||
'<Cmd>lua require("nuwiki.commands")._table_jump_to_cell(%d, %d)<CR>',
|
||||
row,
|
||||
target_idx
|
||||
)
|
||||
end
|
||||
-- Past the final cell. Prefer cycling into the next existing row
|
||||
-- (skipping any separator); only insert a fresh row when we're on the
|
||||
-- table's last row.
|
||||
local _, e_row = find_table_range(row)
|
||||
local next_row = row + 1
|
||||
while next_row <= e_row do
|
||||
local _, next_cells = parse_table_row(vim.fn.getline(next_row))
|
||||
if not is_separator_row(next_cells) then
|
||||
return string.format(
|
||||
'<Cmd>lua require("nuwiki.commands")._table_jump_to_cell(%d, %d)<CR>',
|
||||
next_row,
|
||||
1
|
||||
)
|
||||
end
|
||||
next_row = next_row + 1
|
||||
end
|
||||
return string.format(
|
||||
'<Cmd>lua require("nuwiki.commands")._table_jump_to_cell(%d, %d)<CR>',
|
||||
row,
|
||||
target_idx
|
||||
'<Cmd>lua require("nuwiki.commands")._table_insert_row_below(%d)<CR>',
|
||||
row
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user