Skip to content

fix: getCellSelection throwing error (BLO-1193)#2911

Open
matthewlipski wants to merge 1 commit into
mainfrom
static-toolbar-crash
Open

fix: getCellSelection throwing error (BLO-1193)#2911
matthewlipski wants to merge 1 commit into
mainfrom
static-toolbar-crash

Conversation

@matthewlipski

@matthewlipski matthewlipski commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

TableHandlesExtension.getCellSelection throws an error when the selection is within a table block but not actually a cell selection. For example, the selection can be a gap cursor at the start of the table.

In the static formatting toolbar example, the text alignment buttons call getCellSelection on selection change. In this example, if a table is at the start of the document, you can move the selection to a gap cursor above the table using the up arrow key or clicking in certain places to the side of the table. The text alignment buttons call getCellSelection which errors.

Closes #2748

Rationale

This is an uncommon error, but one that should be fixed either way.

Changes

  • Added additional checks before & after resolving cell positions to ensure they actually point to cells.

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

It seems strange that a button in the formatting toolbar should even need the table handles extension, so we may want to fix this also.

Summary by CodeRabbit

  • Bug Fixes

    • Improved table selection handling for cursor positions outside table cells, including gap cursors near tables and nested blocks.
    • Prevented invalid cell selections when the cursor is not inside a table cell.
  • Tests

    • Added coverage for valid table-cell selections and non-table cursor positions.

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Jul 22, 2026 4:03pm
blocknote-website Ready Ready Preview Jul 22, 2026 4:03pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 22, 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: fc2e88f9-fcd2-4aa9-b029-d6862fb53dd5

📥 Commits

Reviewing files that changed from the base of the PR and between dee7880 and dba1c65.

📒 Files selected for processing (3)
  • packages/core/src/blocks/Table/TableExtension.test.ts
  • packages/core/src/blocks/defaultBlockTypeGuards.ts
  • packages/core/src/extensions/TableHandles/TableHandles.ts

📝 Walkthrough

Walkthrough

Table handle selection now validates resolved positions against actual table cell nodes, preventing invalid gap-cursor positions from reaching document resolution. Tests cover positions beside leading tables, nested blocks, and valid selections inside table cells.

Changes

Table cell selection validation

Layer / File(s) Summary
Validate table cell positions
packages/core/src/blocks/defaultBlockTypeGuards.ts, packages/core/src/extensions/TableHandles/TableHandles.ts
Adds isTableCellNode and uses it with negative-position checks in getCellSelection() to reject positions outside table cells.
Cover table handle selection cases
packages/core/src/blocks/Table/TableExtension.test.ts
Adds tests for gap cursors beside leading tables or nested blocks, plus valid cell-coordinate extraction inside a table cell.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: nperez0111

Poem

A rabbit hops where tables lie,
No crashing cursor leaps awry.
Cells reveal their row and place,
Gap cursors find a safer space.
“Thump!” says Bun, and tests pass bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and directly describes the getCellSelection crash fix.
Description check ✅ Passed The description follows the template and covers summary, rationale, changes, testing, and checklist.
Linked Issues check ✅ Passed The changes address #2748 by preventing out-of-cell selections from resolving and add tests for gap cursors and non-cell selections.
Out of Scope Changes check ✅ Passed All changes are directly related to the table selection crash fix and its tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 static-toolbar-crash

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 Jul 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/mantine

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

commit: dba1c65

@github-actions

github-actions Bot commented Jul 22, 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-2911/

Built to branch gh-pages at 2026-07-22 16:10 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@matthewlipski
matthewlipski requested a review from YousefED July 22, 2026 16:17
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.

RangeError: Position -1 out of range when clicking left margin with table

1 participant