Skip to content

fix(core): strip comments from copied text - #3260

Merged
nperez0111 merged 3 commits into
TypeCellOS:mainfrom
adarshsm:fix/3158-comment-mark-paste
Oct 28, 2026
Merged

nperez0111 merged 3 commits into
TypeCellOS:mainfrom
adarshsm:fix/3158-comment-mark-paste

Conversation

@adarshsm

Copy link
Copy Markdown
Contributor

Summary

Closes #3158.

Copying text that has a comment and pasting it kept the comment mark, with the same thread id. This PR removes comment marks from pasted content, so only the original text stays attached to the thread. This is what the issue asks for, and what Notion does.

Rationale

The comment mark is serialized into the clipboard HTML (<span class="bn-thread-mark" data-bn-thread-id="…">) and parsed back on paste, like any other mark. The pasted text then shows the thread highlight, but the thread's anchor is now two ranges. The comments UI only tracks one position per thread (getUpdatedThreadPositions keeps the smallest from and the largest to), so a copy pasted elsewhere stretches the thread's apparent range between the two places.

Changes

  • comments/extension.ts: add a transformPasted prop to the comments plugin that removes the comment mark from the pasted slice (removeMarkFromFragment).
  • A drop that's the end of a drag-and-drop move (view.dragging.move) is left alone, since the text moves along with its comment and nothing is duplicated. A drag-copy (Alt/Ctrl) is a copy, so it's stripped like a paste.

Impact

  • Pasting copied text (internally or from another BlockNote document) no longer carries comments.
  • Cut and paste goes through the same path, so the comment doesn't follow text that's cut and pasted (moving it by dragging keeps the comment). If you'd rather keep comments on cut and paste, I can special-case it, but it isn't possible to tell a cut from a copy at paste time without extra state.
  • Editors without the comments extension are unaffected, since the prop is part of that extension's plugin.

Testing

  • New packages/core/src/comments/extension.test.ts:
    • copying commented text (selectedFragmentToHTML → pasteHTML) pastes plain text, and the thread is still anchored on the original text only. This fails without the fix (the pasted text carries thread-1).
    • a paste during an internal drag-move keeps the comment.
  • @blocknote/core suite: everything passes except the src/y/** and src/yjs/** suites, which fail at import in my local checkout (TypeError: Node is not a constructor / defaultTransformer is not a function from the installed @y/y), unrelated to this change.
  • vp lint and vp fmt 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.

Copying text that has a comment and pasting it kept the comment mark with
the same thread id. The pasted text was highlighted as part of the thread,
but the thread now had two anchored ranges, and resolving or deleting the
thread had to deal with both.

Strip the comment mark from pasted slices in the comments extension. A
drag-and-drop move keeps its comments, since it moves the text instead of
copying it.

Closes TypeCellOS#3158
@vercel

vercel Bot commented Oct 25, 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 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/diagram-block

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

@blocknote/mantine

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

@blocknote/math-block

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

@blocknote/xl-typst-exporter

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

commit: 6b28176

@YousefED

Copy link
Copy Markdown
Collaborator

Thanks! I think it would be cleaner though if the comment mark is not put on the clipboard at all (so filter-on-copy instead of filter-on-paste?)

@nperez0111
nperez0111 marked this pull request as ready for review October 28, 2026 06:41
@nperez0111 nperez0111 changed the title fix(core): don't paste the comments of copied text fix(core): strip comments from copied text Oct 28, 2026
@nperez0111
nperez0111 merged commit cccb6fa into TypeCellOS:main Oct 28, 2026
18 of 20 checks passed
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.

Copy / paste a text with a comment

3 participants