Skip to content

fix(core): separate blocks with newlines in getSelectedText - #3210

Draft
adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/710-selected-text-block-separator
Draft

adarshsm wants to merge 1 commit into
TypeCellOS:mainfrom
adarshsm:fix/710-selected-text-block-separator

Conversation

@adarshsm

Copy link
Copy Markdown
Contributor

Summary

Closes #710.

editor.getSelectedText() joined the text of every selected block with nothing in between. If you select two paragraphs, "First" and "Second", you get "FirstSecond". With this change you get "First\nSecond".

Rationale

StyleManager.getSelectedText returns tr.doc.textBetween(from, to). Without the third blockSeparator argument, ProseMirror concatenates textblocks directly. Passing "\n" adds one newline between textblocks. Nested block containers and block groups don't add extra newlines, because textBetween only inserts the separator before a textblock (or a leaf block with text), not before every block node.

Changes

  • StyleManager.getSelectedText: pass "\n" as the block separator.
  • JSDoc on BlockNoteEditor.getSelectedText and the manipulating-content.mdx reference: mention the newline between blocks.

Impact

  • Selections within one block are unchanged.
  • The one internal caller is CreateLinkButton, which uses the result as the default link text. Cross-block link creation now gets newline-separated text instead of run-together words.
  • Users who relied on the concatenated output will now see newlines. Since the issue describes that output as a bug, I didn't add an option to keep the old behaviour.

Testing

  • New getSelectedText cases in src/editor/managers/StyleManager.test.ts:
    • a selection over paragraph / paragraph with a nested child / heading returns "First\nSecond\nNested\nThird". On main it returns "FirstSecondNestedThird".
    • a selection inside one paragraph returns the selected text unchanged.
  • packages/core suite: everything passes except the src/y/* / Versioning suites. Those fail at import (Node is not a constructor from @y/y) in my local install (a stale @y/y in node_modules), which is unrelated to this change.
  • vp lint and vp fmt --check are clean on the touched files.

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

None.

🤖 Generated with Claude Code

`getSelectedText` called `doc.textBetween(from, to)` without a block
separator, so a selection across blocks returned the block texts glued
together ("FirstSecond" for two paragraphs "First" and "Second").

Pass "\n" as the block separator so text from each block is on its own
line. Selections inside a single block are unchanged.

Closes TypeCellOS#710
@vercel

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

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: b91981c

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.

editor.getSelectedText() - Missing whitespace between selected text segments crossing blocks boundaries

1 participant