Skip to content

fix: Pasting plain text from VSCode (BLO-366)#2713

Merged
nperez0111 merged 1 commit intomainfrom
vscode-plain-text-paste
May 6, 2026
Merged

fix: Pasting plain text from VSCode (BLO-366)#2713
nperez0111 merged 1 commit intomainfrom
vscode-plain-text-paste

Conversation

@matthewlipski
Copy link
Copy Markdown
Collaborator

@matthewlipski matthewlipski commented May 6, 2026

Summary

When VSCode content is on the clipboard, it stores content in the plain/text MIME type. It also contains a bunch of information about the source, like the language of the code being pasted, which depends on the source file type.

BlockNote always attempts to parse VSCode content as a code block. If this fails for whatever reason, e.g. code blocks are not in the schema, a language wasn't found, etc, it won't paste anything.

This PR makes it so that if handleVSCodePaste is unable to parse the text/plain content as a code block, we attempt to parse it the usual way.

Rationale

While minor, it's not that uncommon for people to have plain text files in VSCode, or files without an ending. Copy/pasting from these into BlockNote is totally broken right now, so this should be fixed.

Changes

  • If handleVSCodePaste returns false, format is set to text/plain and the content is parsed normally.
  • Made handleVSCodePaste for all branches where the content cannot be parsed as a code block.

Impact

N/A

Testing

Our unit testing setup doesn't support adding custom content types to the clipboard the way that VSCode does, so we can't really replicate VSCode clipboard content for testing.

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
    • Improved clipboard paste handling for VS Code formatted content. Code blocks now paste with proper formatting only when a code block node is available; otherwise, content falls back to plain text.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

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

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview May 6, 2026 8:25am
blocknote-website Ready Ready Preview May 6, 2026 8:25am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

The PR modifies clipboard paste handling for VSCode-formatted data. The handleVSCodePaste function is now synchronous and returns false when no codeBlock node exists (previously it would paste plain text). The caller in pasteExtension.ts now checks this return value and falls back to plain text paste if handling fails.

Changes

Clipboard Paste Control Flow

Layer / File(s) Summary
Function Behavior
packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts
handleVSCodePaste is now synchronous. When no codeBlock node exists, it returns false instead of pasting plain text and returning true.
Integration & Fallback
packages/core/src/api/clipboard/fromClipboard/pasteExtension.ts
The vscode-editor-data handler now checks the return value of handleVSCodePaste. If it returns true, paste succeeds; if false, the content falls back to plain text paste by setting format = "text/plain".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested reviewers

  • nperez0111

Poem

🐰 A clipboard's journey, now more graceful and kind,
When VSCode data fades, plain text we find.
No promises broken, just fallback so sweet,
Paste returns false, and the flow stays neat!

🚥 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%. 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 'fix: Pasting plain text from VSCode (BLO-366)' accurately describes the main change: enabling plain text fallback when VSCode paste parsing fails.
Description check ✅ Passed The PR description covers all major template sections: Summary, Rationale, Changes, Impact, Testing, and Checklist are all completed with relevant details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 vscode-plain-text-paste

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts (1)

21-22: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard vscode-editor-data parsing so fallback still works.

JSON.parse can throw for malformed clipboard metadata, which would abort paste handling before pasteExtension can fall back to text/plain. Return false on parse failure instead.

Proposed fix
-  const vscode = event.clipboardData!.getData("vscode-editor-data");
-  const vscodeData = vscode ? JSON.parse(vscode) : undefined;
-  const language = vscodeData?.mode;
+  const vscode = event.clipboardData!.getData("vscode-editor-data");
+  let language: string | undefined;
+  if (vscode) {
+    try {
+      const vscodeData = JSON.parse(vscode) as { mode?: unknown };
+      language =
+        typeof vscodeData.mode === "string" ? vscodeData.mode : undefined;
+    } catch {
+      return false;
+    }
+  }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts` around
lines 21 - 22, Guard the `vscode` JSON parse so malformed `vscode-editor-data`
doesn't throw: wrap the `JSON.parse(vscode)` call in a try/catch (where `vscode`
and `vscodeData` are used) and on any parse error set `vscodeData` to undefined
(or return false from `handleVSCodePaste` immediately) so the function falls
back to `pasteExtension`/`text/plain`; ensure the `language` assignment uses the
safely-parsed `vscodeData?.mode` and that parse failures do not abort paste
handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts`:
- Around line 21-22: Guard the `vscode` JSON parse so malformed
`vscode-editor-data` doesn't throw: wrap the `JSON.parse(vscode)` call in a
try/catch (where `vscode` and `vscodeData` are used) and on any parse error set
`vscodeData` to undefined (or return false from `handleVSCodePaste` immediately)
so the function falls back to `pasteExtension`/`text/plain`; ensure the
`language` assignment uses the safely-parsed `vscodeData?.mode` and that parse
failures do not abort paste handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c1f3f52c-83c6-4927-90f9-1173367f6060

📥 Commits

Reviewing files that changed from the base of the PR and between 50b1328 and 4be8c85.

📒 Files selected for processing (2)
  • packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts
  • packages/core/src/api/clipboard/fromClipboard/pasteExtension.ts

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

Open in StackBlitz

@blocknote/ariakit

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

@blocknote/code-block

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

@blocknote/core

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

@blocknote/mantine

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

@blocknote/react

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

@blocknote/server-util

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

@blocknote/shadcn

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

@blocknote/xl-ai

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

@blocknote/xl-docx-exporter

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

@blocknote/xl-email-exporter

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

@blocknote/xl-multi-column

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

@blocknote/xl-odt-exporter

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

@blocknote/xl-pdf-exporter

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

commit: 4be8c85

@matthewlipski matthewlipski requested a review from nperez0111 May 6, 2026 08:32
Copy link
Copy Markdown
Contributor

@nperez0111 nperez0111 left a comment

Choose a reason for hiding this comment

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

Good catch @matthewlipski

@nperez0111 nperez0111 merged commit bca6680 into main May 6, 2026
23 checks passed
@nperez0111 nperez0111 deleted the vscode-plain-text-paste branch May 6, 2026 12:18
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.

2 participants