Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2755 After modifying the list type and the indentation, the list types within the same list may be inconsistent. #2795

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading