Skip to content

Conversation

@matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Oct 17, 2025

Summary

This PR replaces the moveFirstBlockInColumn function with fixColumnList. While the old function reused a lot of code from the existing backspace keyboard handler for the first block in a column, it was unclear and hard to understand. The new function is much simpler, as it just takes a columnList node and deletes any empty columns. If all columns are empty, the whole node is deleted.

Rationale

Makes the code easier to understand and maintain.

Changes

  • Removed moveFirstBlockInColumn.
  • Added fixColumnList.
  • Updated multi-column keyboard handler and removeAndInsertBlocks.

Impact

N/A

Testing

All existing tests for removing/replacing blocks/columns pass. All cases for backspace handling have been manually tested.

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

@vercel
Copy link

vercel bot commented Oct 17, 2025

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

Project Deployment Preview Updated (UTC)
blocknote Ready Ready Preview Oct 20, 2025 5:34pm
blocknote-website Ready Ready Preview Oct 20, 2025 5:34pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 17, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@2113

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@2113

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@2113

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@2113

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@2113

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@2113

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@2113

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@2113

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@2113

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@2113

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@2113

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@2113

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@2113

commit: 218f22a

@matthewlipski matthewlipski changed the title WIP:fixColumnList feat: Clean up invalid multi-column handling Oct 20, 2025
@matthewlipski matthewlipski marked this pull request as ready for review October 20, 2025 10:35
Comment on lines 121 to 122
const firstColumnEmpty = isEmptyColumn(firstColumn);
const lastColumnEmpty = isEmptyColumn(lastColumn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see what happens when the first & last column are the same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to throw an error in this case. Since if the columnList only has a single non-empty column, this is both an unexpected case that should never happen (PM should automatically add an empty column to make the columnList valid), and it would not be covered by the existing cases.

Comment on lines 61 to 65
for (
let columnIndex = columnList.childCount - 1;
columnIndex >= 0;
columnIndex--
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not just a columnList.children.forEach?

Copy link
Collaborator Author

@matthewlipski matthewlipski Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh imo it's way more intuitive in this case to use a for loop since we can go backwards. That way we don't have to worry about having to terminate early.

The bigger issue though is that forEach doesn't account for children being removed - e.g. removing child 0 should mean that child 3 now becomes child 2, but it remains child 3 in forEach, and the index ends up being wrong. So overall it's just way easier to use the reverse for loop.

@nperez0111
Copy link
Contributor

@matthewlipski, Unsure what the right thing to do here is, but when dragging a block out of a column, I'd expect the column to collapse unless it had content. Maybe the fixColumns should run as an appendTransaction in a plugin so we don't have to specifically run it everywhere that a column may be touched in some way?

Screen.Recording.2025-10-20.at.17.05.06.mov

@matthewlipski
Copy link
Collaborator Author

Good point, though I would do that in a separate PR though since I want to get it out soon so we can close #1323, and I feel like figuring out how to nicely get the positions of changed tables after each transaction might take some time.

@matthewlipski matthewlipski changed the base branch from multi-column-block-delete-fix to main October 23, 2025 11:33
@matthewlipski matthewlipski changed the base branch from main to multi-column-block-delete-fix October 23, 2025 11:34
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.

2 participants