fix: the issue where link preview would be pasted to the next line when pasting (#16)

This commit is contained in:
Kilu.He 2025-01-10 18:43:01 +08:00 committed by GitHub
parent b4147b1fe9
commit 4c71e621cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 5 deletions

View File

@ -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;