Conversation
`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
|
@adarshsm is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
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: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
getSelectionCutBlocksslices the document betweentr.selection.$fromandtr.selection.$to. In ProseMirror those only cover a selection's first range. ACellSelectionhas 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/multipleTableCellssnapshot 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", withblockCutAtStartset.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$fromand max$toover all ofselection.rangesbefore the existing boundary adjustments.getCellSelectionandgetSelectionBoundingBoxalready handleCellSelections 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_metacovering the table.Impact
Results with a 2×3 table (
a b c / d e f):fonlyconlya b c, cut at endb/eeonlyb c / d e, cut at both endsOne question for you:
_meta.startPos/endPosis 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 (asCellSelection.content()/ the clipboard path does), I can switch the table content over to that.Testing
vp test --run src/unit/core/selection/getSelectionintests: the updatedmultipleTableCellssnapshot fails onmainand passes with the fix. The other 21 cases (single cell, text selections across tables, etc.) are unchanged.testsunit run passes. The only exceptions are theblocknoteHTML/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.packages/coreunit suite passes (run withNODE_OPTIONS=--no-experimental-webstorageon Node 26).vp fmt --checkandvp lint --type-awareare clean on the changed file.Checklist
🤖 Generated with Claude Code