From 8231d99c5301893291bf12ccea3cfba60a74d2b0 Mon Sep 17 00:00:00 2001 From: Jiuqing Song Date: Fri, 28 Jul 2023 14:21:21 -0700 Subject: [PATCH] Content Model Fix 214383 (#1986) --- .../processors/delimiterProcessor.ts | 4 +- .../processors/delimiterProcessorTest.ts | 50 +++++++++++++++++-- .../lib/context/DomToModelSettings.ts | 2 +- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/delimiterProcessor.ts b/packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/delimiterProcessor.ts index e08119495ee..24000ce0ef3 100644 --- a/packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/delimiterProcessor.ts +++ b/packages-content-model/roosterjs-content-model-dom/lib/domToModel/processors/delimiterProcessor.ts @@ -8,12 +8,14 @@ import { handleRegularSelection } from './childProcessor'; * @param element * @param context */ -export const delimiterProcessor: ElementProcessor = (group, element, context) => { +export const delimiterProcessor: ElementProcessor = (group, element, context) => { let index = 0; const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, element); for (let child = element.firstChild; child; child = child.nextSibling) { handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset); + + delimiterProcessor(group, child, context); index++; } diff --git a/packages-content-model/roosterjs-content-model-dom/test/domToModel/processors/delimiterProcessorTest.ts b/packages-content-model/roosterjs-content-model-dom/test/domToModel/processors/delimiterProcessorTest.ts index d263d690cd3..310d3d984c8 100644 --- a/packages-content-model/roosterjs-content-model-dom/test/domToModel/processors/delimiterProcessorTest.ts +++ b/packages-content-model/roosterjs-content-model-dom/test/domToModel/processors/delimiterProcessorTest.ts @@ -1,8 +1,10 @@ import * as delimiterProcessorFile from '../../../lib/domToModel/processors/childProcessor'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; +import { createRange } from 'roosterjs-editor-dom'; import { delimiterProcessor } from '../../../lib/domToModel/processors/delimiterProcessor'; import { DomToModelContext } from 'roosterjs-content-model-types'; +import { SelectionRangeTypes } from 'roosterjs-editor-types'; describe('delimiterProcessor', () => { let context: DomToModelContext; @@ -13,16 +15,56 @@ describe('delimiterProcessor', () => { it('Delimiter', () => { const doc = createContentModelDocument(); - const br = document.createElement('span'); - br.append(document.createTextNode('')); + const span = document.createElement('span'); + span.append(document.createTextNode('')); spyOn(delimiterProcessorFile, 'handleRegularSelection'); - delimiterProcessor(doc, br, context); + delimiterProcessor(doc, span, context); expect(doc).toEqual({ blockGroupType: 'Document', blocks: [], }); - expect(delimiterProcessorFile.handleRegularSelection).toHaveBeenCalledTimes(2); + expect(delimiterProcessorFile.handleRegularSelection).toHaveBeenCalledTimes(3); + }); + + it('Delimiter with selection', () => { + const doc = createContentModelDocument(); + const text = document.createTextNode('test'); + const span = document.createElement('span'); + const span2 = document.createElement('span'); + const div = document.createElement('div'); + + span.appendChild(text); + + div.appendChild(span); + div.appendChild(span2); + + context.rangeEx = { + type: SelectionRangeTypes.Normal, + ranges: [createRange(text, 0, span2, 0)], + areAllCollapsed: false, + }; + + delimiterProcessor(doc, span, context); + + expect(doc).toEqual({ + blockGroupType: 'Document', + blocks: [ + { + blockType: 'Paragraph', + isImplicit: true, + format: {}, + segments: [ + { + segmentType: 'SelectionMarker', + isSelected: true, + format: {}, + }, + ], + }, + ], + }); + expect(context.isInSelection).toBeTrue(); }); }); diff --git a/packages-content-model/roosterjs-content-model-types/lib/context/DomToModelSettings.ts b/packages-content-model/roosterjs-content-model-types/lib/context/DomToModelSettings.ts index acc35880eb8..0041452c466 100644 --- a/packages-content-model/roosterjs-content-model-types/lib/context/DomToModelSettings.ts +++ b/packages-content-model/roosterjs-content-model-types/lib/context/DomToModelSettings.ts @@ -95,7 +95,7 @@ export type ElementProcessorMap = { /** * Processor for Inline Readonly Delimiters */ - delimiter?: ElementProcessor; + delimiter?: ElementProcessor; }; /**