Skip to content

Commit

Permalink
Content Model Fix 214383 (#1986)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Jul 28, 2023
1 parent 9e94b66 commit 8231d99
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { handleRegularSelection } from './childProcessor';
* @param element
* @param context
*/
export const delimiterProcessor: ElementProcessor<HTMLSpanElement> = (group, element, context) => {
export const delimiterProcessor: ElementProcessor<Node> = (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++;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type ElementProcessorMap = {
/**
* Processor for Inline Readonly Delimiters
*/
delimiter?: ElementProcessor<HTMLSpanElement>;
delimiter?: ElementProcessor<Node>;
};

/**
Expand Down

0 comments on commit 8231d99

Please sign in to comment.