Skip to content

Commit

Permalink
Fix #2755 (#2795)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Sep 13, 2024
1 parent c872e31 commit 5480a82
Show file tree
Hide file tree
Showing 2 changed files with 309 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ export function setModelIndentation(
//if block has only one level, there is not need to check if it is multilevel selection
} else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {
if (isIndent) {
const lastLevel = block.levels[block.levels.length - 1];
const threadIdx = thread.indexOf(block);
const previousItem = thread[threadIdx - 1];
const nextItem = thread[threadIdx + 1];
const levelLength = block.levels.length;
const lastLevel = block.levels[levelLength - 1];
const newLevel: ContentModelListLevel = createListLevel(
lastLevel?.listType || 'UL',
lastLevel?.format
lastLevel?.format,
previousItem && previousItem.levels.length > levelLength
? previousItem.levels[levelLength].dataset
: nextItem && nextItem.levels.length > levelLength
? nextItem.levels[levelLength].dataset
: undefined
);

updateListMetadata(newLevel, metadata => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as getListAnnounceData from '../../../lib/modelApi/list/getListAnnounceData';
import { FormatContentModelContext } from 'roosterjs-content-model-types';
import { ContentModelDocument, FormatContentModelContext } from 'roosterjs-content-model-types';
import { setModelIndentation } from '../../../lib/modelApi/block/setModelIndentation';
import {
createContentModelDocument,
Expand Down Expand Up @@ -899,6 +899,303 @@ describe('indent', () => {
});
expect(getListAnnounceDataSpy).not.toHaveBeenCalled();
});

it('Indent and follow previous item style', () => {
const model: ContentModelDocument = {
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{ format: {}, dataset: { a: 'c' }, listType: 'OL' },
],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{ segmentType: 'SelectionMarker', format: {}, isSelected: true },
],
},
],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
],
};

setModelIndentation(model, 'indent');

expect(model).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{ format: {}, dataset: { a: 'c' }, listType: 'OL' },
],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{ segmentType: 'SelectionMarker', format: {}, isSelected: true },
],
},
],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{
format: {},
dataset: { a: 'c', editingInfo: '{"applyListStyleFromLevel":true}' },
listType: 'OL',
},
],
},
],
});
});

it('Indent and follow next item style', () => {
const model: ContentModelDocument = {
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{ segmentType: 'SelectionMarker', format: {}, isSelected: true },
],
},
],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{ format: {}, dataset: { a: 'c' }, listType: 'OL' },
],
},
],
};

setModelIndentation(model, 'indent');

expect(model).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{ segmentType: 'SelectionMarker', format: {}, isSelected: true },
],
},
],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{
format: {},
dataset: { a: 'c', editingInfo: '{"applyListStyleFromLevel":true}' },
listType: 'OL',
},
],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{ format: {}, dataset: { a: 'c' }, listType: 'OL' },
],
},
],
});
});

it('Indent, no style to follow', () => {
const model: ContentModelDocument = {
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{ segmentType: 'SelectionMarker', format: {}, isSelected: true },
],
},
],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
],
};

setModelIndentation(model, 'indent');

expect(model).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [{ format: {}, dataset: { a: 'b' }, listType: 'OL' }],
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{ segmentType: 'SelectionMarker', format: {}, isSelected: true },
],
},
],
format: {},
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
levels: [
{ format: {}, dataset: { a: 'b' }, listType: 'OL' },
{
format: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
listType: 'OL',
},
],
},
],
});
});
});

describe('outdent', () => {
Expand Down

0 comments on commit 5480a82

Please sign in to comment.