Fix table deletion and improve multi-cell selection UI#16
Open
PttCodingMan wants to merge 1 commit intomainfrom
Open
Fix table deletion and improve multi-cell selection UI#16PttCodingMan wants to merge 1 commit intomainfrom
PttCodingMan wants to merge 1 commit intomainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, anddeleteSelectedCellsCommandfrom@milkdown/preset-gfmthat were causing silent failures on ragged tables.Implemented custom deletion functions:
deleteTableNode(): Direct node-range deletion that bypassesprosemirror-tablesTableMap, allowing deletion of malformed tablesdeleteRowNode(): Deletes entire row or table if it's the last rowdeleteColumnAtIndex(): Intelligently removes a column by deleting individual cells, handling ragged rows and removing rows that would become emptycountRows(): Helper to count valid rows in a tableUpdated
locateTable()return value: Changed from returningtablePosto returning the fulltableandrownode 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::afterpseudo-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.selectedCellclass 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