Skip to content

fix(core): include every selected cell in getSelectionCutBlocks - #3152

Draft
adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/1922-cut-blocks-cell-selection
Draft

adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/1922-cut-blocks-cell-selection

Conversation

@adarshsm

@adarshsm adarshsm commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1922. If several table cells are selected, editor.getSelectionCutBlocks() returns a table block that holds only one cell. This happens even when the whole table is selected.

Rationale

getSelectionCutBlocks slices the document between tr.selection.$from and tr.selection.$to. In ProseMirror those only cover a selection's first range. A CellSelection has one range per selected cell, and prosemirror-tables puts the head cell's range first. So the slice was just the head cell.

The existing regular/multipleTableCells snapshot records this. It selects Cell 1 → Cell 4 of a 2×2 table (the whole table), and the expected output was a one-cell table containing only "Table Cell 4", with blockCutAtStart set.

When there's a selection, the AI extension builds its request from getSelectionCutBlocks(true) (xl-ai/src/api/aiRequest/builder.ts), so a cell selection would give it the same single cell. I haven't tested the AI path itself.

Changes

  • packages/core/src/api/blockManipulation/selections/selection.ts: take the min $from and max $to over all of selection.ranges before the existing boundary adjustments. getCellSelection and getSelectionBoundingBox already handle CellSelections this way. For single-range selections (text, node, all) nothing changes.
  • tests/.../getSelection/__snapshots__/regular/multipleTableCells.json: now holds the whole table (both rows, both cells each), with no cut flags and _meta covering the table.

Impact

Results with a 2×3 table (a b c / d e f):

cell selection before after
whole table f only whole table, not cut
first row c only a b c, cut at end
column b/e e only b c / d e, cut at both ends

One question for you: _meta.startPos/endPos is a single document range, so a rectangle that isn't contiguous in document order (like a single column) comes back as everything between its first and last cell. That's how it lines up with _meta. If you'd rather the blocks hold exactly the selected rectangle (as CellSelection.content() / the clipboard path does), I can switch the table content over to that.

Testing

  • vp test --run src/unit/core/selection/getSelection in tests: the updated multipleTableCells snapshot fails on main and passes with the fix. The other 21 cases (single cell, text selections across tables, etc.) are unchanged.
  • The full tests unit run passes. The only exceptions are the blocknoteHTML/math* snapshots, which differ on this machine because of a KaTeX class-name difference in my local install. They're unrelated, and I didn't include them.
  • Full packages/core unit suite passes (run with NODE_OPTIONS=--no-experimental-webstorage on Node 26). vp fmt --check and vp lint --type-aware are clean on the changed file.

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)

🤖 Generated with Claude Code

`getSelectionCutBlocks` sliced the document between `selection.$from` and
`selection.$to`, which only cover a selection's first range. A
`CellSelection` has one range per cell and puts the head cell first, so
selecting several table cells (even the whole table) returned a table
holding just the head cell. Span all of the selection's ranges instead.

The `multipleTableCells` snapshot recorded the old result (only
"Table Cell 4" for a Cell 1 → Cell 4 selection) and now holds the
whole table.

Closes TypeCellOS#1922
@vercel

vercel Bot commented Oct 4, 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 4, 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
  • Autopilot · 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 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 7377772

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.

Invalid selection provided by getSelectionCutBlocks in tables

1 participant