Skip to content

Commit

Permalink
Content Model: Move copy entity related code to copyPastePlugin (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Sep 28, 2023
1 parent 4de6e53 commit 3e3429a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ export const handleEntitySegment: ContentModelSegmentHandler<ContentModelEntity>
function preprocessEntity(entityModel: ContentModelEntity, context: ModelToDomContext) {
let { id, type, isReadonly, wrapper } = entityModel;

if (!context.allowCacheElement) {
wrapper = wrapper.cloneNode(true /*deep*/) as HTMLElement;
wrapper.style.color = wrapper.style.color || 'inherit';
wrapper.style.backgroundColor = wrapper.style.backgroundColor || 'inherit';
}

const entity: Entity | null =
id && type
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export default class ContentModelCopyPastePlugin implements PluginWithState<Copy
ColorTransformDirection.DarkToLight
);

result.style.color = result.style.color || 'inherit';
result.style.backgroundColor =
result.style.backgroundColor || 'inherit';

return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ describe('ContentModelCopyPastePlugin |', () => {
const cloneEntity = options.includeCachedElement(wrapper, 'entity');

expect(cloneCache).toBeUndefined();
expect(cloneEntity).toEqual(wrapper);
expect(cloneEntity.outerHTML).toBe(
'<span class="_Entity _EType_Entity _EId_Entity _EReadonly_1" contenteditable="false" style="color: inherit; background-color: inherit;"></span>'
);
expect(cloneEntity).not.toBe(wrapper);
expect(transformToDarkColorSpy).toHaveBeenCalledTimes(1);
expect(transformToDarkColorSpy).toHaveBeenCalledWith(
Expand Down

0 comments on commit 3e3429a

Please sign in to comment.