Skip to content

Commit

Permalink
Resume triggering the BeforePasteEvent when Paste Type is equal to Pl…
Browse files Browse the repository at this point in the history
…ainText (#2911)

* Trigger BeforePaste on PlainText

* Fix tests
  • Loading branch information
BryanValverdeU authored Dec 16, 2024
1 parent 5024d9a commit 61f4923
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ export function generatePasteOptionFromPlugins(
containsBlockElements: !!htmlFromClipboard.containsBlockElements,
};

return pasteType == 'asPlainText'
? event
: editor.triggerEvent('beforePaste', event, true /* broadcast */);
return editor.triggerEvent('beforePaste', event, true /* broadcast */);
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ describe('generatePasteOptionFromPlugins', () => {
it('PasteType=asPlainText', () => {
triggerPluginEventSpy.and.callFake((core, event) => {
Object.assign(event, mockedResult);

return event;
});
const result = generatePasteOptionFromPlugins(
editor,
Expand All @@ -236,24 +238,16 @@ describe('generatePasteOptionFromPlugins', () => {
);

expect(result).toEqual({
fragment: mockedFragment,
domToModelOption: {
additionalAllowedTags: [],
additionalDisallowedTags: [],
additionalFormatParsers: {},
formatParserOverride: {},
processorOverride: {},
styleSanitizers: {},
attributeSanitizers: {},
},
pasteType: 'asPlainText',
eventType: 'beforePaste',
clipboardData: mockedClipboardData,
htmlBefore,
htmlAfter,
htmlAttributes: mockedMetadata,
clipboardData: 'CLIPBOARDDATA' as any,
fragment: 'FragmentResult' as any,
htmlBefore: 'HTMLBEFORE',
htmlAfter: 'HTMLAFTER',
htmlAttributes: 'METADATA' as any,
pasteType: 'TypeResult' as any,
domToModelOption: 'OptionResult' as any,
containsBlockElements: false,
});
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(0);
expect(triggerPluginEventSpy).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ describe('paste with content model & paste plugin', () => {

paste(editor!, clipboardData, 'asPlainText');

expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(0);
expect(WordDesktopFile.processPastedContentFromWordDesktop).toHaveBeenCalledTimes(0);
expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(1);
expect(addParserF.addParser).toHaveBeenCalledTimes(9);
expect(WordDesktopFile.processPastedContentFromWordDesktop).toHaveBeenCalledTimes(1);
});

it('Word Online | Plain Text', () => {
Expand All @@ -234,9 +234,9 @@ describe('paste with content model & paste plugin', () => {

paste(editor!, clipboardData, 'asPlainText');

expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(0);
expect(WacComponents.processPastedContentWacComponents).toHaveBeenCalledTimes(0);
expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(2);
expect(addParserF.addParser).toHaveBeenCalledTimes(11);
expect(WacComponents.processPastedContentWacComponents).toHaveBeenCalledTimes(1);
});

it('Excel Online | Plain Text', () => {
Expand All @@ -246,7 +246,7 @@ describe('paste with content model & paste plugin', () => {
paste(editor!, clipboardData, 'asPlainText');

expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(4);
expect(ExcelF.processPastedContentFromExcel).toHaveBeenCalledTimes(0);
});

Expand All @@ -257,7 +257,7 @@ describe('paste with content model & paste plugin', () => {
paste(editor!, clipboardData, 'asPlainText');

expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(4);
expect(ExcelF.processPastedContentFromExcel).toHaveBeenCalledTimes(0);
});

Expand All @@ -268,8 +268,8 @@ describe('paste with content model & paste plugin', () => {
paste(editor!, clipboardData, 'asPlainText');

expect(setProcessorF.setProcessor).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(0);
expect(PPT.processPastedContentFromPowerPoint).toHaveBeenCalledTimes(0);
expect(addParserF.addParser).toHaveBeenCalledTimes(4);
expect(PPT.processPastedContentFromPowerPoint).toHaveBeenCalledTimes(1);
});

it('Verify the event data is not lost', () => {
Expand Down

0 comments on commit 61f4923

Please sign in to comment.