Commit Graph

6 Commits

Author SHA1 Message Date
milvasic 0ad53f9dd3 refactor(table): rename resolveTableIndex, fix escapeCell backslash handling, remove redundant cast
- Rename `resolveTableIndex` useMemo value to `currentTableIndex` in Table.tsx
  so the name reflects a computed value rather than an action; update all
  references (callbacks, dependency arrays, JSDoc comment)

- Fix `escapeCell` in markdown-table.ts: replace the single-char lookbehind
  regex `(?<!\\)|` with a character loop that counts consecutive backslashes
  before each pipe and only inserts an escape when the count is even, mirroring
  the parser logic and correctly handling sequences like `\\|`

- Remove redundant `as ColumnAlignment` type assertion in `createEmptyTable`;
  TypeScript infers `\"none\"` correctly via contextual typing from the return type

- Add regression test for the `\\|` round-trip case in markdown-table.test.ts
2026-03-24 18:42:47 +01:00
milvasic 26dec86b70 fix(markdown-table): handle escaped backslashes before pipe separators; use @/ alias in test import
- Rewrite parseRow to count consecutive backslashes before each pipe so
  that `\\|` (escaped backslash + unescaped pipe) is correctly treated as
  a column separator. The previous lookbehind regex (?<!\\)| only checked
  the single character immediately before the pipe, causing it to fail for
  an even number of preceding backslashes.
- Update test file import from relative `./markdown-table` to the project
  alias `@/utils/markdown-table` for consistency with frontend conventions.
2026-03-24 18:33:16 +01:00
milvasic 004e667b7a fix(table): escape pipe chars in cells on serialize, unescape on parse
- escapeCell() replaces unescaped | with \| before writing each cell,
  applied in both width calculation and formatRow so padding is accurate
- parseRow unescapes \| back to | after splitting on unescaped pipes
- Adds round-trip regression test for cells containing pipe characters

Addresses coderabbitai review comment on PR #5680.
2026-03-24 18:33:16 +01:00
milvasic 314ab03715 fix(table): use GFM AST parser for findAllTables; fix lints
- Replace regex-based TABLE_LINE scan in findAllTables with a proper
  GFM markdown AST lookup using mdast-util-from-markdown + mdast-util-gfm
  + micromark-extension-gfm + unist-util-visit (all already in deps).
  Tables without leading/trailing pipes (e.g. 'A | B\n--- | ---\n1 | 2')
  are now correctly detected via node.position.start/end.offset.
- Add regression test asserting pipe-less GFM table is found with correct
  start/end offsets.
- Fix parseMarkdownTable to split on unescaped pipes only (lookbehind).
- Fix import order in Table.tsx (Biome organizeImports).
- Fix useless escape \- → - in TableEditorDialog.tsx sort regex.
- Reformat long normalize/compareFn lines to satisfy Biome formatter.
2026-03-24 18:33:16 +01:00
milvasic a759acc6a7 fix: address PR review comments for table editor
Bugs:
- Fix replaceNthTable off-by-one: findAllTables now uses truly exclusive
  end index (start + text.length) so content.slice(start, end) === text
- Replace fragile DOM-based table index resolution with AST-based approach
  using node.position.start.offset from hast ReactMarkdownProps

Architecture:
- Unify TableEditorDialog instances: InsertMenu no longer manages its own
  dialog, instead calls onOpenTableEditor from parent MemoEditor which
  owns the single shared dialog instance
- Remove onInsertText prop chain (InsertMenu → EditorToolbar → MemoEditor)
  replaced by onOpenTableEditor

Other improvements:
- Add i18n: all hardcoded English strings now use useTranslate()/t() with
  new editor.table.* keys in en.json
- Fix useCallback [props] dependency that defeated memoization (removed
  with dialog unification)
- Use stable row IDs (monotonic counter) as React keys instead of array
  indices in TableEditorDialog
- Replace hardcoded MONO_FONT constant with Tailwind font-mono class
  (maps to project's --font-mono CSS variable)
- Add 28 vitest tests for markdown-table.ts covering parse, serialize,
  findAllTables, replaceNthTable, createEmptyTable with edge cases
- Add vitest dev dependency with test/test:watch scripts
2026-03-24 18:32:49 +01:00
Milan Vasić b4c2c180b8 feat: table editor dialog for visual markdown table editing
Add a dialog-based table editor to create and edit markdown tables via a
visual grid instead of raw pipe-delimited text.

Features:
- Visual grid with inputs for headers and cells; add/remove rows and columns
- Sort columns (asc/desc, text and numeric); tab navigation (new row at end)
- Insert column/row between columns/rows via hover zones and + buttons with
  blue highlight lines clipped to table bounds
- Sticky header with solid background; square headers; monospace cell font
- Row numbers with insert zones; delete row at row end; delete column with
  spacing from insert button; Add row/Add column in footer and below table
- Delete table button on rendered tables (with confirm); edit pencil opens
  dialog with parsed data; always-visible sort/delete at 40% opacity
- Fixed-size dialog (56rem x 44rem); /table slash command and Table in
  InsertMenu open dialog; Command.action support for dialog-based commands

New: TableEditorDialog.tsx, utils/markdown-table.ts. Integration in
SlashCommands, EditorContent, InsertMenu, MemoContent Table.

Made-with: Cursor
2026-03-24 18:27:17 +01:00