Skip to content

Fix table deletion and improve multi-cell selection UI#16

Open
PttCodingMan wants to merge 1 commit intomainfrom
claude/fix-table-selection-deletion-NfHZC
Open

Fix table deletion and improve multi-cell selection UI#16
PttCodingMan wants to merge 1 commit intomainfrom
claude/fix-table-selection-deletion-NfHZC

Conversation

@PttCodingMan
Copy link
Copy Markdown
Owner

Summary

This PR improves table manipulation in the editor by replacing Milkdown's built-in table deletion commands with custom implementations that handle malformed/ragged tables, and adds visual feedback for multi-cell selections.

Key Changes

  • Removed unused imports: Eliminated imports of selectRowCommand, selectColCommand, selectTableCommand, and deleteSelectedCellsCommand from @milkdown/preset-gfm that were causing silent failures on ragged tables.

  • Implemented custom deletion functions:

    • deleteTableNode(): Direct node-range deletion that bypasses prosemirror-tables TableMap, allowing deletion of malformed tables
    • deleteRowNode(): Deletes entire row or table if it's the last row
    • deleteColumnAtIndex(): Intelligently removes a column by deleting individual cells, handling ragged rows and removing rows that would become empty
    • countRows(): Helper to count valid rows in a table
  • Updated locateTable() return value: Changed from returning tablePos to returning the full table and row node objects with their position information, enabling more precise deletion operations.

  • Refactored deletion handlers: Replaced command-based deletion (select-then-delete) with direct calls to the new custom functions in the runAction() method.

  • Enhanced multi-cell selection visibility: Added CSS styling with .selectedCell::after pseudo-element to display a semi-transparent overlay on selected cells, making range selections visually distinct from single-cell selections. This works with prosemirror-tables' native .selectedCell class decoration.

Implementation Details

The new deletion approach directly manipulates the document tree rather than relying on Milkdown's table selection and deletion commands, which silently fail on tables with irregular structure (missing cells, uneven rows). The custom functions walk the table structure, calculate precise cell/row positions, and apply deletions in reverse order to avoid position shifts.

https://claude.ai/code/session_01YQpRGeviHUSZJ84cQJukFt

Bypass prosemirror-tables' TableMap-based select-then-delete flow for
the table tooltip's row/column/table delete actions. The gfm preset
commands (selectRow/Col/TableCommand + deleteSelectedCellsCommand) rely
on TableMap consistency and silently no-op on ragged or otherwise
malformed tables, which left the tooltip's per-row and per-column
delete buttons unable to clean up such tables.

The new helpers operate directly on the document range of the row,
column cells, or table node — so they work regardless of TableMap
reported problems. Edge cases handled:
- Deleting the only row of a table deletes the table.
- A column delete that would empty a row drops the row instead.
- A column delete that would empty all rows deletes the table.

Also style prosemirror-tables' .selectedCell decoration so that
multi-cell selections (drag across cells) actually look selected; the
viewer was previously only showing the cursor cell's native text
selection, making range selections look like single-cell selections.

https://claude.ai/code/session_01YQpRGeviHUSZJ84cQJukFt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants