Skip to content

Commit

Permalink
Patch: Fix paste issue for repaste (#2516)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Mar 20, 2024
1 parent 79dc022 commit d615454
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cloneModelForPaste, mergePasteContent } from '../../utils/paste/mergePasteContent';
import { convertInlineCss } from '../../utils/convertInlineCss';
import { createPasteFragment } from '../../utils/paste/createPasteFragment';
import { generatePasteOptionFromPlugins } from '../../utils/paste/generatePasteOptionFromPlugins';
import { mergePasteContent } from '../../utils/paste/mergePasteContent';
import { retrieveHtmlInfo } from '../../utils/paste/retrieveHtmlInfo';
import type {
PasteType,
Expand All @@ -26,7 +26,9 @@ export function paste(
const trustedHTMLHandler = editor.getTrustedHTMLHandler();

if (!clipboardData.modelBeforePaste) {
clipboardData.modelBeforePaste = editor.getContentModelCopy('connected');
clipboardData.modelBeforePaste = cloneModelForPaste(
editor.getContentModelCopy('connected')
);
}

// 1. Prepare variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ const EmptySegmentFormat: Required<ContentModelSegmentFormat> = {
textColor: '',
underline: false,
};

const CloneOption: CloneModelOptions = {
includeCachedElement: (node, type) => (type == 'cache' ? undefined : node),
};

/**
* @internal
*/
export function cloneModelForPaste(model: ContentModelDocument) {
return cloneModel(model, CloneOption);
}

/**
* @internal
*/
Expand All @@ -45,7 +53,7 @@ export function mergePasteContent(
editor.formatContentModel(
(model, context) => {
if (clipboardData.modelBeforePaste) {
const clonedModel = cloneModel(clipboardData.modelBeforePaste, CloneOption);
const clonedModel = cloneModelForPaste(clipboardData.modelBeforePaste);
model.blocks = clonedModel.blocks;
}

Expand Down

0 comments on commit d615454

Please sign in to comment.