Conversation
Dropping a dragged row or column rebuilt the table from block JSON via updateBlock, which drops marks that aren't styles, like comments. Move the cells in place with prosemirror-tables' moveTableRow/moveTableColumn instead; cell attributes, including column widths, move with the cells. Fixes TypeCellOS#2904
|
@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
@blocknote/xl-typst-exporter
commit: |
|
This is great to have @adarshsm, I have been meaning to implement this for a long time but thought it would be complicated. Can we add more extensive testing of this though, specifically I would want tests for advanced table test cases like split and merged cells: https://www.blocknotejs.org/docs/features/blocks/tables#split-cells since those are the most tricky to have working. I'm sure that prosemirror-tables handles them properly, but I want to make sure that our tests properly ensure that |
Summary
Fixes #2904. When you drag a table row or column to a new position, any comments on the text in that table are lost.
Rationale
TableHandlesView.dropHandlermoved the row or column by rebuilding the table's rows withmoveRow/moveColumn, then writing them back witheditor.updateBlock. That round trip goes through block JSON, which only keeps styles. Marks that aren't styles, such as thecommentmark, get dropped. As @nperez0111 said in the issue, the move should happen in ProseMirror without going through BlockNote JSON.Changes
dropHandlernow moves the cells in place using prosemirror-tables'moveTableRow/moveTableColumn, which are already available through the^1.8.5dependency. Adding and removing rows and columns already works this way, viaaddRowBefore,deleteColumn, and so on.addRowOrColumn/setCellSelectionuse.getAbsoluteTableCells, just asmoveRow/moveColumndid.colwidthattribute, so they move with the cells. This also removes an in-placespliceonthis.state.block.content.columnWidths.canRowBeDraggedInto/canColumnBeDraggedIntochecks and the finalsetTextCursorPositionare unchanged.moveRow/moveColumnintables.tsstay as they are. They are still exported and tested.Impact
Dropping a row or column should give the same table as before, except that marks now survive the move. To check this, I compared the new drop result against the old
moveRow/moveColumn+updateBlockoutput on these tables, and the resulting tables were identical in every case:Testing
packages/core/src/extensions/TableHandles/TableHandles.test.ts(jsdom). It builds a 2×2 table with a comment on one cell, sets up the handles state the way hovering does, and callsdropHandler, once for a row and once for a column. Before this change both tests fail because the moved cell has lost its comment (expected [['c','d'],['a','b']] to deeply equal [['c','d'],['a@thread','b']]). With the change both pass. The column test also checks thatcolumnWidthsfollow the moved column.vp test runinpackages/core: all existing tests pass.vp lint/vp fmtare clean on the changed files.Checklist
🤖 Generated with Claude Code