feat(13.1-B): table rewriters — insert, align, moveColumn
Closes the table-rewriter cluster from SPEC §13.1. Server-side (ops module): - `render_blank_table(cols, rows)` — pure templating: header row, separator `|--|--|--|`, then `rows` empty data rows. Wired through `table_insert` which dispatches a `TextEdit` at the cursor. - `table_align_edit` — locates the `TableNode` containing the cursor line, computes max width per column across every row, re-emits the table with each cell space-padded to its column's width. The parser drops `|---|---|` separator rows but sets `TableNode.has_header`; the renderer re-inserts a padded separator after the header so the result still parses. - `table_move_column_edit` — column-under-cursor swap with the left or right neighbour (`dir = "left" | "right"`). Cursor column is computed by counting pipe separators before the cursor's byte offset on the row's line. Column widths swap alongside the data so the post-swap table stays aligned. No-ops cleanly when the swap would fall off either edge. Editor glue: - `lua/nuwiki/commands.lua` / `autoload/nuwiki/commands.vim` — the three "not yet implemented" stubs are replaced with real LSP dispatchers. `table_insert` accepts optional `cols`/`rows` arguments (defaults: 3×2). - Default keymaps `gqq` / `gq1` / `gww` / `gw1` now call `table_align`; `<A-Left>` / `<A-Right>` call `table_move_column_left` / `_right`. No more "deferred" notifications on the table keys. Tests: 8 new in `cluster_b_table_rewriters.rs` — blank-table shape (3×2 + 1×1), column-width alignment with separator-row repad, swap- right shape, swap-left clamp at column 0, no-table-found fallbacks, COMMANDS list completeness. Total 410 Rust tests pass; clippy clean; Neovim keymap harness still 20/20. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+27
-3
@@ -474,9 +474,33 @@ function M.list_change_lvl(direction)
|
||||
M.list_change_level(delta, false)
|
||||
end
|
||||
|
||||
M.table_insert = _not_yet(':VimwikiTable')
|
||||
M.table_move_column_left = _not_yet(':VimwikiTableMoveColumnLeft')
|
||||
M.table_move_column_right = _not_yet(':VimwikiTableMoveColumnRight')
|
||||
-- §13.1 Cluster B — table rewriters.
|
||||
|
||||
function M.table_insert(cols, rows)
|
||||
cols = tonumber(cols) or 3
|
||||
rows = tonumber(rows) or 2
|
||||
local p = pos_args()[1]
|
||||
p.cols = cols
|
||||
p.rows = rows
|
||||
exec('nuwiki.table.insert', { p })
|
||||
end
|
||||
|
||||
function M.table_align()
|
||||
exec('nuwiki.table.align', pos_args())
|
||||
end
|
||||
|
||||
function M.table_move_column_left()
|
||||
local p = pos_args()[1]
|
||||
p.dir = 'left'
|
||||
exec('nuwiki.table.moveColumn', { p })
|
||||
end
|
||||
|
||||
function M.table_move_column_right()
|
||||
local p = pos_args()[1]
|
||||
p.dir = 'right'
|
||||
exec('nuwiki.table.moveColumn', { p })
|
||||
end
|
||||
|
||||
M.colorize = _not_yet(':VimwikiColorize')
|
||||
|
||||
-- §13.1 Cluster C — link helpers.
|
||||
|
||||
@@ -255,12 +255,12 @@ function M.attach(bufnr, mappings)
|
||||
|
||||
-- ===== Tables =====
|
||||
if on('table_editing') then
|
||||
map('n', 'gqq', deferred(':VimwikiTableAlignQ'), { desc = 'nuwiki: table align (deferred)' }, bufnr)
|
||||
map('n', 'gq1', deferred(':VimwikiTableAlignQ1'), { desc = 'nuwiki: table align row1 (deferred)' }, bufnr)
|
||||
map('n', 'gww', deferred(':VimwikiTableAlignW'), { desc = 'nuwiki: table align wide (deferred)' }, bufnr)
|
||||
map('n', 'gw1', deferred(':VimwikiTableAlignW1'), { desc = 'nuwiki: table align row1 wide (deferred)' }, bufnr)
|
||||
map('n', '<A-Left>', deferred(':VimwikiTableMoveColumnLeft'), { desc = 'nuwiki: table col left (deferred)' }, bufnr)
|
||||
map('n', '<A-Right>', deferred(':VimwikiTableMoveColumnRight'), { desc = 'nuwiki: table col right (deferred)' }, bufnr)
|
||||
map('n', 'gqq', cmd.table_align, { desc = 'nuwiki: align table' }, bufnr)
|
||||
map('n', 'gq1', cmd.table_align, { desc = 'nuwiki: align table' }, bufnr)
|
||||
map('n', 'gww', cmd.table_align, { desc = 'nuwiki: align table (wide)' }, bufnr)
|
||||
map('n', 'gw1', cmd.table_align, { desc = 'nuwiki: align table (wide)' }, bufnr)
|
||||
map('n', '<A-Left>', cmd.table_move_column_left, { desc = 'nuwiki: move column left' }, bufnr)
|
||||
map('n', '<A-Right>', cmd.table_move_column_right, { desc = 'nuwiki: move column right' }, bufnr)
|
||||
end
|
||||
|
||||
-- ===== HTML =====
|
||||
|
||||
Reference in New Issue
Block a user