Skip to content

Commit

Permalink
Merge branch 'master' into u/jisong/262677_2
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Mar 27, 2024
2 parents 1376b9e + 77454eb commit 8286c5b
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
57 changes: 57 additions & 0 deletions packages/roosterjs-content-model-core/test/editor/EditorTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as cloneModel from 'roosterjs-content-model-dom/lib/modelApi/editing/cloneModel';
import * as createDomToModelContextWithConfig from 'roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext';
import * as createEditorCore from '../../lib/editor/core/createEditorCore';
import * as createEmptyModel from 'roosterjs-content-model-dom/lib/modelApi/creators/createEmptyModel';
import * as domToContentModel from 'roosterjs-content-model-dom/lib/domToModel/domToContentModel';
import * as transformColor from 'roosterjs-content-model-dom/lib/domUtils/style/transformColor';
import { CachedElementHandler, EditorCore, Rect } from 'roosterjs-content-model-types';
import { ChangeSource, tableProcessor } from 'roosterjs-content-model-dom';
Expand Down Expand Up @@ -240,6 +242,61 @@ describe('Editor', () => {
expect(resetSpy).toHaveBeenCalledWith();
});

it('getContentModelCopy, clean, custom logical root', () => {
const div = document.createElement('div');
const mockedEditorContext = 'EDITORCONTEXT' as any;
const mockedModelContext = 'MODELCONTEXT' as any;
const mockedModel = 'MODEL' as any;
const createEditorContextSpy = jasmine
.createSpy('createEditorContext')
.and.returnValue(mockedEditorContext);
const resetSpy = jasmine.createSpy('reset');
const mockedCore = {
logicalRoot: 'LOGICAL',
physicalRoot: 'PHYSICAL',
plugins: [],
darkColorHandler: {
updateKnownColor: updateKnownColorSpy,
reset: resetSpy,
},
lifecycle: {
isDarkMode: false,
},
api: {
createEditorContext: createEditorContextSpy,
setContentModel: setContentModelSpy,
},
environment: {
domToModelSettings: {
calculated: undefined,
},
},
} as any;

createEditorCoreSpy.and.returnValue(mockedCore);

const editor = new Editor(div);

const createDomToModelContextWithConfigSpy = spyOn(
createDomToModelContextWithConfig,
'createDomToModelContextWithConfig'
).and.returnValue(mockedModelContext);
const domToContentModelSpy = spyOn(domToContentModel, 'domToContentModel').and.returnValue(
mockedModel
);

const model = editor.getContentModelCopy('clean');
expect(model).toBe(mockedModel);
expect(createDomToModelContextWithConfigSpy).toHaveBeenCalledWith(
mockedCore.environment.domToModelSettings.calculated,
mockedEditorContext
);
expect(domToContentModelSpy).toHaveBeenCalledWith(
mockedCore.physicalRoot,
mockedModelContext
);
});

it('getEnvironment', () => {
const div = document.createElement('div');
const mockedEnvironment = 'ENVIRONMENT' as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const deleteList: DeleteSelectionStep = context => {
item &&
index >= 0 &&
paragraph.segments[0] == marker &&
item.blockGroupType == 'ListItem' &&
(paragraph.segments.length == 1 ||
(paragraph.segments.length == 2 && paragraph.segments[1].segmentType == 'Br'))
item.blockGroupType == 'ListItem'
) {
item.levels = [];
context.deleteResult = 'range';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,79 @@ describe('deleteList', () => {
});
expect(result.deleteResult).toEqual('range');
});

it('delete list if the cursor is before text', () => {
const model: ContentModelDocument = {
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
format: {
listStyleType: '"1. "',
},
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{
segmentType: 'SelectionMarker',
format: {},
isSelected: true,
},
{
segmentType: 'Text',
text: 'text',
format: {},
},
{
segmentType: 'Br',
format: {},
},
],
isImplicit: true,
},
],
levels: [
{
listType: 'OL',
format: {},
dataset: {},
},
],
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: true,
format: {},
},
},
],
};
const result = deleteSelection(model, [deleteList]);
normalizeContentModel(model);
expect(result.deleteResult).toEqual('range');
expect(model).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'Paragraph',
segments: [
{
segmentType: 'SelectionMarker',
isSelected: true,
format: {},
},
{
segmentType: 'Text',
text: 'text',
format: {},
},
],
format: {},
isImplicit: false,
},
],
});
});
});

0 comments on commit 8286c5b

Please sign in to comment.