Skip to content

Commit

Permalink
Fix issue that paste will remove cache (#2900)
Browse files Browse the repository at this point in the history
* Fix issue that paste will remove cache

* improve
  • Loading branch information
JiuqingSong authored Dec 10, 2024
1 parent 334e038 commit 0f788b1
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export function cloneModelForPaste(model: ReadonlyContentModelDocument) {
/**
* @internal
*/
export function mergePasteContent(editor: IEditor, eventResult: BeforePasteEvent) {
export function mergePasteContent(
editor: IEditor,
eventResult: BeforePasteEvent,
isFirstPaste: boolean
) {
const {
fragment,
domToModelOption,
Expand All @@ -48,7 +52,7 @@ export function mergePasteContent(editor: IEditor, eventResult: BeforePasteEvent

editor.formatContentModel(
(model, context) => {
if (clipboardData.modelBeforePaste) {
if (!isFirstPaste && clipboardData.modelBeforePaste) {
const clonedModel = cloneModelForPaste(clipboardData.modelBeforePaste);
model.blocks = clonedModel.blocks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export function paste(
pasteTypeOrGetter: PasteTypeOrGetter = 'normal'
) {
editor.focus();
let isFirstPaste = false;

if (!clipboardData.modelBeforePaste) {
isFirstPaste = true;

editor.formatContentModel(model => {
clipboardData.modelBeforePaste = cloneModelForPaste(model);

Expand Down Expand Up @@ -64,7 +68,7 @@ export function paste(
convertInlineCss(eventResult.fragment, htmlFromClipboard.globalCssRules);

// 6. Merge pasted content into main Content Model
mergePasteContent(editor, eventResult);
mergePasteContent(editor, eventResult, isFirstPaste);
}

function createDOMFromHtml(
Expand Down
Loading

0 comments on commit 0f788b1

Please sign in to comment.