From 4c71e621cf598f40a260ec3350cf7186c1f85531 Mon Sep 17 00:00:00 2001 From: "Kilu.He" <108015703+qinluhe@users.noreply.github.com> Date: Fri, 10 Jan 2025 18:43:01 +0800 Subject: [PATCH] fix: the issue where link preview would be pasted to the next line when pasting (#16) --- src/components/editor/plugins/withPasted.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/editor/plugins/withPasted.ts b/src/components/editor/plugins/withPasted.ts index 97f3113..8cedd0e 100644 --- a/src/components/editor/plugins/withPasted.ts +++ b/src/components/editor/plugins/withPasted.ts @@ -61,9 +61,14 @@ export const withPasted = (editor: ReactEditor) => { } } - const currentBlockId = node.blockId as string; - - CustomEditor.addBelowBlock(editor as YjsEditor, currentBlockId, BlockType.LinkPreview, { url: text } as LinkPreviewBlockData); + // const currentBlockId = node.blockId as string; + // + // CustomEditor.addBelowBlock(editor as YjsEditor, currentBlockId, BlockType.LinkPreview, { url: text } as LinkPreviewBlockData); + insertFragment(editor, [{ + type: BlockType.LinkPreview, + data: { url: text } as LinkPreviewBlockData, + children: [{ text: '' }], + }]); return true; } @@ -105,7 +110,7 @@ export const withPasted = (editor: ReactEditor) => { return editor; }; -export function insertHtmlData(editor: ReactEditor, data: DataTransfer) { +export function insertHtmlData (editor: ReactEditor, data: DataTransfer) { const html = data.getData('text/html'); if (html) { @@ -120,7 +125,7 @@ export function insertHtmlData(editor: ReactEditor, data: DataTransfer) { return false; } -function insertFragment(editor: ReactEditor, fragment: Node[], options = {}) { +function insertFragment (editor: ReactEditor, fragment: Node[], options = {}) { console.log('insertFragment', fragment, options); if (!beforePasted(editor)) return;