Skip to content

fix: insertInlineContent adding content after cursor (BLO-1356) - #3112

Open
matthewlipski wants to merge 3 commits into
mainfrom
insert-inline-content-fix
Open

matthewlipski wants to merge 3 commits into
mainfrom
insert-inline-content-fix

Conversation

@matthewlipski

@matthewlipski matthewlipski commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR makes it so that insertInlineContent inserts the content just before the cursor rather than just after.

Closes #3064

Rationale

This is more in-line with expected behavior.

Changes

  • Set the tiptapEditor.isEditorContentInitialized flag on mount.

Impact

N/A

Testing

Added component test.

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

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Typing after inserting styled text now continues in the correct position, including after the editor is remounted.

@vercel

vercel Bot commented Sep 23, 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 25, 2026 4:37pm UTC
blocknote-website Ready Ready Preview Sep 25, 2026 4:37pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 8d6dbc65-508c-49cb-872f-3782f0122154

📥 Commits

Reviewing files that changed from the base of the PR and between 908f0b5 and 0a37b4d.

📒 Files selected for processing (2)
  • packages/core/src/editor/BlockNoteEditor.ts
  • packages/react/src/schema/ReactStyleSpec.browser.test.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

BlockNoteEditor now tracks content initialization during mount and unmount. A React browser test checks typing after styled text insertion, including after an API remount. The React Vitest configuration excludes browser test files.

Changes

React style caret positioning

Layer / File(s) Summary
Editor mounting and caret regression test
packages/core/src/editor/BlockNoteEditor.ts, packages/react/src/schema/ReactStyleSpec.browser.test.tsx, packages/react/vite.config.ts
BlockNoteEditor exposes and updates the content-initialization flag during mount and unmount. The browser test checks typing after styled text insertion, including after an API remount. Vitest excludes browser test files from the React package test run.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: yousefed

Merge Risk: ⚪ Minimal · up to 0a37b

The change preserves the initialization ordering needed for styled React marks, and its regression test remains in the CI browser suite. No merge-blocking risk is established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 0a37b

The change appears limited to editor mounting and caret behavior. No new security exposure was identified, but the renderer’s failure behavior has not been fully verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The observed effect is confined to an editor instance’s mounting and styled-text editing flow; the inspected change does not establish tenant, service, credential, or deployment exposure.

Trust Boundaries and Controls

  • inferred — The inspected React caller passes a DOM element to the existing editor lifecycle methods. No new trust or authority transition is established by the flag writes in that path.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the insertInlineContent cursor-positioning fix and matches the pull request objective.
Description check ✅ Passed The description includes all required sections and explains the rationale, primary change, impact, testing, and checklist status. The Changes section could mention the browser test and Vite configurat…
Linked Issues check ✅ Passed Issue [#3064] requires the caret to remain after text inserted with a custom React style. BlockNoteEditor.mount now sets isEditorContentInitialized after TipTap mounts, and unmount clears it bef…
Out of Scope Changes check ✅ Passed The changed editor flag, its type declaration, the React-style browser test, and the Vitest exclusion all support the fix for [#3064]. No unrelated change is demonstrated.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

A rabbit taps the editor pane,
Styled text appears in tidy train.
It hops away, then comes once more,
And types its words where they belong.
The caret stays; the burrow’s bright!

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 23, 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-3112/

Built to branch gh-pages at 2026-09-25 16:48 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@pkg-pr-new

pkg-pr-new Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 0a37b4d

Comment on lines 368 to 377
const tiptapEditor: ReactRenderer["editor"] = editor._tiptapEditor;
tiptapEditor.contentComponent = portalManager;
if (element) {
editor.mount(element);
// Render subsequent React node/mark views synchronously so their
// contentDOM is attached when ProseMirror places the selection.
tiptapEditor.isEditorContentInitialized = true;
} else {
tiptapEditor.isEditorContentInitialized = false;
editor.unmount();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm confused how the issue relates to this fix. Also, shouldn't this be done as part of the editor.mount & editor.unmount functions?

@matthewlipski matthewlipski Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

When inserting a React mark, is attaches contentDOM async via a ref. When isEditorContentInitialized = false, the PM state/view correctly update the document and view, and the issue comes when PM tries to sync its selection with the browser. Because the content is not yet rendered, the browser is unable to set the selection to the given offset, so the whole selection update is rejected. Rendering synchronously causes the content to be rendered straight away, so you don't get issues with PM syncing its internal selection with the browser's.

This branch was successfully deployed

2 active deployments
Preview – blocknote-website — 0a37b4df Deployed Sep 25, 2026 by vercel[bot]
Preview – blocknote — 0a37b4df Deployed Sep 25, 2026 by vercel[bot]
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.

Caret moves before text inserted with a custom React style

2 participants