Skip to content

fix: Error using moveBlocks in columns (BLO-1109)#2842

Open
matthewlipski wants to merge 1 commit into
mainfrom
move-blocks-columns-error
Open

fix: Error using moveBlocks in columns (BLO-1109)#2842
matthewlipski wants to merge 1 commit into
mainfrom
move-blocks-columns-error

Conversation

@matthewlipski

@matthewlipski matthewlipski commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes an edge case when using moveBlocks with columns. moveBlocks first removes the target block(s), then inserts it/them above/below the previous/next block. In the removal step, fixColumns is called for all affected column lists, collapsing them or individual columns when they're empty.

This causes an error in the following case:

<column>
  <paragraph></paragraph>
  <paragraph>Paragraph</paragraph>
</column>

When moving the non-empty paragraph block up, it's first removed. This leaves the column with a single empty paragraph, which fixColumns reads as an empty column, and so collapses it. Upon re-insertion, the reference block no longer exists and an error is thrown. This also happens when the order of the 2 blocks is flipped and the non-empty one is moved down.

The fix for this is to defer calling fixColumns after the re-insertion. So a fixColumns option has been added to removeAndInsertBlocks so that the fixColumns function can be suppressed when removing blocks.

Closes #2594

Rationale

This is a bug.

Changes

See above.

Impact

N/A

Testing

Added unit tests.

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

Additional Notes

N/A

Summary by CodeRabbit

  • Bug Fixes

    • Improved block movement operations within multi-column layouts to better preserve column structure integrity.
    • Fixed edge cases when repositioning blocks past empty siblings within columns.
  • Tests

    • Added test coverage for block movement scenarios involving empty sibling elements in multi-column structures.

@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Error Error Jun 8, 2026 9:24am
blocknote-website Error Error Jun 8, 2026 9:24am

Request Review

@matthewlipski matthewlipski requested a review from nperez0111 June 8, 2026 08:47
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ceb7b5ba-6c24-45bd-9878-7d923373fd1a

📥 Commits

Reviewing files that changed from the base of the PR and between ec9c151 and d0ea3cc.

⛔ Files ignored due to path filters (1)
  • packages/xl-multi-column/src/test/commands/__snapshots__/moveBlocks.test.ts.snap is excluded by !**/*.snap, !**/__snapshots__/**
📒 Files selected for processing (3)
  • packages/core/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts
  • packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts
  • packages/xl-multi-column/src/test/commands/moveBlocks.test.ts

📝 Walkthrough

Walkthrough

This PR refactors block movement to defer column-list repairs until after insertion. The removeAndInsertBlocks utility now accepts an options flag to skip intermediate column fixing and returns affected columnList IDs. The moveBlocks command uses this to skip column corrections during removal, then re-applies fixes post-insertion via a transaction callback, with new tests validating empty sibling behavior.

Changes

Block Move Column-Fixing Refactor

Layer / File(s) Summary
removeAndInsertBlocks column-fixing options and return type
packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts
removeAndInsertBlocks gains optional options.fixColumns parameter (defaults enabled) and returns affectedColumnLists: string[]. During removal, affected columnList IDs are collected; column fixing is conditionally applied or deferred based on the option, allowing callers to handle fixes separately.
moveBlocks transaction callback and deferred column fixing
packages/core/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts
moveBlocks now uses editor.transact((tr) => ...) callback and imports the updated removeAndInsertBlocks and fixColumnList utilities. The move algorithm skips column fixing during removal (fixColumns: false), then iterates affectedColumnLists post-insertion to re-apply column corrections at each affected list position.
Test coverage for moving past empty sibling nodes
packages/xl-multi-column/src/test/commands/moveBlocks.test.ts
Test imports updated to include beforeEach, with new test section verifying moveBlocksUp and moveBlocksDown behavior on blocks adjacent to empty paragraphs within column lists. Snapshot-based tests confirm no exceptions and expected document structure after deferred column fixes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TypeCellOS/BlockNote#2718: Adds node.check() validation during node creation in the shared block insertion logic that this PR refactors.
  • TypeCellOS/BlockNote#2723: Earlier API/behavior changes to moveBlocksUp/Down pathways that this PR's transaction and column-fixing refactor extends.

Suggested reviewers

  • nperez0111
  • YousefED

Poem

🐰 Column fixes deferred, the transaction flows clear,
Blocks move without hiccups, no rushing through here!
Empty siblings no trouble—we fix them at last,
A refactored choreography, perfectly cast! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: resolving an error that occurs when using moveBlocks in columns, with the associated ticket reference.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch move-blocks-columns-error

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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 and usage tips.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-2842/

Built to branch gh-pages at 2026-06-08 08:53 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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.

Multi-columns errors when moving blocks

1 participant