Repository navigation
Conversation
The multi-column drop handler removed the dragged blocks and then created or updated the column list with separate editor calls, so each dispatched its own transaction. When the two edits weren't adjacent, prosemirror-history put them in separate undo groups: the first undo only reverted the column change, leaving the dragged blocks deleted, and a second undo was needed to bring them back. Run the removal and the column list change in one `editor.transact` call so the whole drop is one transaction and one undo step. Closes TypeCellOS#3197
|
@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: true
Thanks 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: |
|
Closing as superseded by #3231, which makes both column-edge drop mutation paths atomic and fixes #3197. After merging current main locally and resolving the overlapping implementation changes in favor of main, only this PR's additional regression tests remain. Thanks for the fix and regression coverage! |
Summary
Closes #3197.
Dropping a block on the left or right edge of another block (which creates a column list or adds a column) took two undos to revert. The first undo removed the column change but left the dragged block deleted, so the block disappeared until a second undo brought it back. With this change, one undo reverts the whole drop.
Rationale
createMultiColumnHandleDropPlugin'shandleDropfirst callseditor.removeBlocks(...)to take the dragged blocks out of their old position. It then callseditor.replaceBlocks(...)oreditor.updateBlock(...)to build the column list. Each of those calls runs its owneditor.transact, so the drop dispatches two transactions.prosemirror-history merges consecutive transactions into one undo event only when their changed ranges are adjacent. A block dragged from elsewhere in the document usually isn't adjacent to the drop target, so the drop becomes two undo events. Undoing the newer one restores the target and leaves the removal in place.
The reporter's suggestion in the issue (wrapping both steps in
editor.transact()) is what this PR does.Changes
multiColumnHandleDropPlugin.ts: both branches (adding a column to an existing column list, and creating a new column list) now run the removal and the column-list change inside oneeditor.transact(() => ...). The nestedtransactcalls inremoveBlocks/replaceBlocks/updateBlockreuse the outer transaction, so the drop dispatches once. The logic inside is unchanged apart from indentation.Impact
onChangelisteners see a single change instead of two.Testing
New
undoing an edge dropcases insrc/test/extensions/columnDrop.test.ts, using the existingdropOnEdgehelper:paragraph-2onparagraph-1's edge (creates a column list;column-list-0sits between them)paragraph-0oncolumn-1's edge (adds a column;paragraph-1sits between them)Each test checks that the drop changed the document and that one
editor.undo()restores it. The test movesDate.nowforward for the drop so it starts its own undo group and isn't merged with thebeforeEachdocument setup.On
mainboth cases fail the same way as the issue: after one undo, the dragged block (paragraph-2/paragraph-0) is missing from the document. With this change both pass.Full
@blocknote/xl-multi-columnsuite: 123 passed, 5 skipped.vp lintandvp fmt --checkare clean on the touched files.Screenshots/Video
n/a
Checklist
Additional Notes
I only ran the jsdom suite locally, not the browser drag-and-drop tests (
columnDrop.browser.test.ts).🤖 Generated with Claude Code