Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resume triggering the BeforePasteEvent when Paste Type is equal to PlainText #2911

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading