Skip to content

fix(xl-multi-column): undo an edge drop in a single step - #3207

Draft
adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/3197-multicolumn-drop-undo
Draft

adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/3197-multicolumn-drop-undo

Conversation

@adarshsm

Copy link
Copy Markdown
Contributor

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's handleDrop first calls editor.removeBlocks(...) to take the dragged blocks out of their old position. It then calls editor.replaceBlocks(...) or editor.updateBlock(...) to build the column list. Each of those calls runs its own editor.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 one editor.transact(() => ...). The nested transact calls in removeBlocks / replaceBlocks / updateBlock reuse the outer transaction, so the drop dispatches once. The logic inside is unchanged apart from indentation.

Impact

  • Only the edge-drop path of the multi-column extension is affected. Regular drops are still left to ProseMirror.
  • The document after a drop is the same as before. The only difference is that it's one transaction, so onChange listeners see a single change instead of two.

Testing

  • New undoing an edge drop cases in src/test/extensions/columnDrop.test.ts, using the existing dropOnEdge helper:

    • drop paragraph-2 on paragraph-1's edge (creates a column list; column-list-0 sits between them)
    • drop paragraph-0 on column-1's edge (adds a column; paragraph-1 sits between them)

    Each test checks that the drop changed the document and that one editor.undo() restores it. The test moves Date.now forward for the drop so it starts its own undo group and isn't merged with the beforeEach document setup.

  • On main both 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-column suite: 123 passed, 5 skipped. vp lint and vp fmt --check are clean on the touched files.

Screenshots/Video

n/a

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature (n/a)

Additional Notes

I only ran the jsdom suite locally, not the browser drag-and-drop tests (columnDrop.browser.test.ts).

🤖 Generated with Claude Code

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
@vercel

vercel Bot commented Oct 16, 2026

Copy link
Copy Markdown

@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3207

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3207

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3207

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3207

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3207

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3207

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3207

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3207

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3207

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3207

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3207

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3207

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3207

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3207

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3207

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3207

commit: 3772301

This branch has not been deployed

No deployments
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.

Undoing a block move into a multi-column layout removes the block until a second undo

1 participant