Skip to content

Commit bca6680

Browse files
fix: Pasting plain text from VSCode (BLO-366) (#2713)
1 parent 50b1328 commit bca6680

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

packages/core/src/api/clipboard/fromClipboard/handleVSCodePaste.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { EditorView } from "prosemirror-view";
22

3-
export async function handleVSCodePaste(
4-
event: ClipboardEvent,
5-
view: EditorView,
6-
) {
3+
export function handleVSCodePaste(event: ClipboardEvent, view: EditorView) {
74
const { schema } = view.state;
85

96
if (!event.clipboardData) {
@@ -17,8 +14,7 @@ export async function handleVSCodePaste(
1714
}
1815

1916
if (!schema.nodes.codeBlock) {
20-
view.pasteText(text);
21-
return true;
17+
return false;
2218
}
2319

2420
const vscode = event.clipboardData!.getData("vscode-editor-data");

packages/core/src/api/clipboard/fromClipboard/pasteExtension.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ function defaultPasteHandler({
5757
}
5858

5959
if (format === "vscode-editor-data") {
60-
handleVSCodePaste(event, editor.prosemirrorView);
61-
return true;
60+
// If VSCode clipboard data cannot be parsed as a code block, try parsing
61+
// `text/plain` as a fallback.
62+
if (handleVSCodePaste(event, editor.prosemirrorView)) {
63+
return true;
64+
}
65+
66+
format = "text/plain";
6267
}
6368

6469
if (format === "Files") {

0 commit comments

Comments
 (0)