Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/core/src/api/clipboard/fromClipboard/pasteExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
BlockNoteEditor,
BlockNoteEditorOptions,
} from "../../../editor/BlockNoteEditor";
import { isMarkdown } from "../../parsers/markdown/detectMarkdown.js";
import {
BlockSchema,
InlineContentSchema,
Expand All @@ -13,7 +14,6 @@ import {
import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
import { handleFileInsertion } from "./handleFileInsertion.js";
import { handleVSCodePaste } from "./handleVSCodePaste.js";
import { isMarkdown } from "../../parsers/markdown/detectMarkdown.js";

function defaultPasteHandler({
event,
Expand All @@ -26,6 +26,24 @@ function defaultPasteHandler({
prioritizeMarkdownOverHTML: boolean;
plainTextAsMarkdown: boolean;
}) {
// Special case for code blocks, as they do not support any rich text
// formatting, so we force pasting plain text.
const isInCodeBlock = editor.transact(
(tr) =>
tr.selection.$from.parent.type.spec.code &&
tr.selection.$to.parent.type.spec.code
);

if (isInCodeBlock) {
const data = event.clipboardData?.getData("text/plain");

if (data) {
editor.pasteText(data);

return true;
}
}

let format: (typeof acceptedMIMETypes)[number] | undefined;
for (const mimeType of acceptedMIMETypes) {
if (event.clipboardData!.types.includes(mimeType)) {
Expand Down
Loading