Skip to content

Commit

Permalink
Fix issue that paste will remove cache
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Dec 7, 2024
1 parent 0d6f734 commit 9cb73c8
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export class EventViewPlugin extends SidePanePluginImpl<EventViewPane, SidePaneE

onPluginEvent(e: PluginEvent) {
this.getComponent(component => component.addEvent(e));

if (e.eventType == 'rewriteFromModel') {
console.log('-----Removed-----');
e.removedBlockElements.map(console.log);
console.log('-----Added-----');
e.addedBlockElements.map(console.log);
}
}

getComponentProps(base: SidePaneElementProps) {
Expand Down
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 @@ -24,8 +24,11 @@ export function paste(
editor.focus();

const trustedHTMLHandler = editor.getTrustedHTMLHandler();
let isFirstPaste = false;

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

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

Expand Down Expand Up @@ -67,7 +70,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 9cb73c8

Please sign in to comment.