Skip to content

refactor(core): use the new position helpers in the keyboard shortcuts - #3101

Open
YousefED wants to merge 1 commit into
refactor/block-info-apifrom
block-info-api/position-helpers
Open

YousefED wants to merge 1 commit into
refactor/block-info-apifrom
block-info-api/position-helpers

Conversation

@YousefED

Copy link
Copy Markdown
Collaborator

Three follow-ups on top of #3051, all behaviour-preserving. Based on that branch, so the diff is just these changes.

1. tableContentCaretPos no longer escapes the module

Both callers in KeyboardShortcutsExtension checked contentKind === "table" themselves and then called the table helper — re-making the decision blockEdgePos already makes:

if (info.contentKind === "table") {
  ...setTextSelection(tableContentCaretPos(info.content, "end"))
} else if (info.contentKind === "none") {
  ...setNodeSelection(info.content.beforePos)
} else {
  ...setTextSelection(info.content.afterPos - 1)
}

All three arms are blockEdgePos, whose non-table path returns exactly contentStart / contentEnd. Each site is now one call plus the null case — content with no caret, i.e. an image — which is the only thing the helper can't decide for you. The +4 table offset is back to living in one place instead of three, and the function is module-private again.

2. The keyboard shortcuts use contentStart / contentEnd

BlockInfo gained those fields in #3051 precisely so callers stop writing the arithmetic, but this file still did it by hand in twelve places (content.beforePos + 1, content.afterPos - 1) — every one a "is the caret at the start/end of this block's content?" check.

Replacing them turned out to make content unused in five of the destructures, so those shrank too:

const { block, content, contentStart } = blockInfo;      const { block, contentStart } = blockInfo;

3. A comment on getInsertionPos's lazy-blockGroup branch

Reading if (!info.children) it isn't obvious why hardcoding wrapIn: blockGroup is safe, or why hasContent is tested when it can't be false. Both follow from the BlockInfo union — the container arm makes children required, so only a regular block reaches that branch, and the hasContent test is there to narrow the union so content can be read. The comment says so.

Verification

Behaviour-preserving, checked against both main and #3051 with two differential harnesses — identical scenarios run on each branch and the outputs diffed:

result
core: 1,025 scenarios (keyboard at many offsets over 8 document shapes, block API, navigation, conversions, selection, undo/redo) vs #3051 before these changes 0 differences
core: same, vs main 0 differences
columns: 737 scenarios over 4 layouts, vs #3051 before these changes 0 differences

Plus core 796, multi-column 82, tests 908, type-aware lint clean.

Net −56 / +39 across the two files.

🤖 Generated with Claude Code

Three follow-ups on the BlockInfo refactor, all behaviour-preserving.

`tableContentCaretPos` is no longer exported: both callers checked
`contentKind === "table"` themselves and then called it, duplicating the
branch `blockEdgePos` already makes. They now ask `blockEdgePos` for the
edge, so the table offset lives in one place instead of three.

The keyboard shortcuts computed a block's content edges by hand in twelve
places (`content.beforePos + 1` / `content.afterPos - 1`) rather than
reading `contentStart` / `contentEnd`, which the refactor added for
exactly that. Replacing them left `content` unused in five destructures.

`getInsertionPos`'s lazy-blockGroup branch says why only a regular block
reaches it, so `wrapIn: blockGroup` reads as implied rather than assumed,
and why the `hasContent` check is there to narrow the union.
@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
blocknote Ready Ready Preview Sep 21, 2026 10:00am UTC
blocknote-website Ready Ready Preview Sep 21, 2026 10:00am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 8ca9e744-b948-4847-b5bc-f2c30f0945e6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 Sep 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 862e4ea

@github-actions

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-3101/

Built to branch gh-pages at 2026-09-21 10:08 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.

1 participant