Skip to content

Commit

Permalink
Fix Excel Border issue when pasting (#2121)
Browse files Browse the repository at this point in the history
* init

* itChromeOnly
  • Loading branch information
BryanValverdeU authored Oct 5, 2023
1 parent 05fe924 commit badefc5
Show file tree
Hide file tree
Showing 6 changed files with 2,308 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import addParser from '../utils/addParser';
import { isNodeOfType } from 'roosterjs-content-model-dom';
import { moveChildNodes } from 'roosterjs-editor-dom';
import { setProcessor } from '../utils/setProcessor';
import type ContentModelBeforePasteEvent from '../../../../publicTypes/event/ContentModelBeforePasteEvent';
import type { TrustedHTMLHandler } from 'roosterjs-editor-types';

Expand Down Expand Up @@ -60,6 +61,20 @@ export function processPastedContentFromExcel(
format.borderTop = DEFAULT_BORDER_STYLE;
}
});

setProcessor(event.domToModelOption, 'child', (group, element, context) => {
const segmentFormat = { ...context.segmentFormat };
if (group.blockGroupType === 'TableCell' && group.format.textColor) {
context.segmentFormat.textColor = group.format.textColor;
}

context.defaultElementProcessors.child(group, element, context);

if (group.blockGroupType === 'TableCell' && group.format.textColor) {
context.segmentFormat = segmentFormat;
delete group.format.textColor;
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Content Model Paste Plugin Test', () => {
trustedHTMLHandler
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 3);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(0);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);
expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1);
});

Expand Down Expand Up @@ -141,7 +141,7 @@ describe('Content Model Paste Plugin Test', () => {
trustedHTMLHandler
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(0);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);
expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1);
});

Expand All @@ -157,7 +157,7 @@ describe('Content Model Paste Plugin Test', () => {
trustedHTMLHandler
);
expect(addParser.default).toHaveBeenCalledTimes(DEFAULT_TIMES_ADD_PARSER_CALLED + 1);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(0);
expect(setProcessor.setProcessor).toHaveBeenCalledTimes(1);
expect(chainSanitizerCallbackFile.default).toHaveBeenCalledTimes(1);
});

Expand Down
Loading

0 comments on commit badefc5

Please sign in to comment.