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 #2734 by Setting List Metadata applyListStyleFromLevel: true when toggling a list #2743

Merged
merged 4 commits into from
Jul 11, 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 @@ -6,6 +6,7 @@ import {
mutateBlock,
normalizeContentModel,
setParagraphNotImplicit,
updateListMetadata,
} from 'roosterjs-content-model-dom';
import type {
ContentModelListItem,
Expand Down Expand Up @@ -121,6 +122,17 @@ export function setListType(

mutateBlock(parent).blocks.splice(index, 1, newListItem);
existingListItems.push(newListItem);

const levelIndex = newListItem.levels.length - 1;
const level = mutateBlock(newListItem).levels[levelIndex];

if (level) {
updateListMetadata(level, metadata =>
Object.assign({}, metadata, {
applyListStyleFromLevel: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides here, when do we set this metadata to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other place we set this metadata is when indenting a List. In setModelIndentation.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I tested, and I did not find any regressions.

})
);
}
} else {
existingListItems.forEach(
x => (mutateBlock(x).levels[0].format.marginBottom = '0px')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('indent', () => {
marginTop: undefined,
textAlign: undefined,
},
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
},
],
blocks: [para],
Expand Down Expand Up @@ -138,7 +138,9 @@ describe('indent', () => {
marginTop: '0px',
textAlign: undefined,
},
dataset: {},
dataset: {
editingInfo: '{"applyListStyleFromLevel":true}',
},
},
],
blocks: [para],
Expand Down Expand Up @@ -364,7 +366,7 @@ describe('indent', () => {
marginTop: undefined,
textAlign: undefined,
},
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
},
],
blocks: [para3],
Expand Down Expand Up @@ -420,7 +422,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
startNumberOverride: 1,
direction: 'rtl',
Expand Down Expand Up @@ -500,7 +502,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
startNumberOverride: 1,
direction: undefined,
Expand Down Expand Up @@ -529,7 +531,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
direction: undefined,
marginBottom: undefined,
Expand Down Expand Up @@ -584,7 +586,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
startNumberOverride: 1,
direction: undefined,
Expand Down Expand Up @@ -641,7 +643,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
startNumberOverride: 1,
direction: undefined,
Expand Down Expand Up @@ -669,7 +671,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
startNumberOverride: undefined,
direction: undefined,
Expand Down Expand Up @@ -697,7 +699,7 @@ describe('indent', () => {
levels: [
{
listType: 'OL',
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {
direction: undefined,
marginBottom: undefined,
Expand Down Expand Up @@ -779,7 +781,7 @@ describe('indent', () => {
marginTop: undefined,
textAlign: undefined,
},
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
},
],
formatHolder: {
Expand Down Expand Up @@ -809,7 +811,7 @@ describe('indent', () => {
marginTop: undefined,
textAlign: undefined,
},
dataset: {},
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
},
],
formatHolder: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as setListType from '../../../lib/modelApi/list/setListType';
import { IEditor } from 'roosterjs-content-model-types';
import { toggleNumbering } from '../../../lib/publicApi/list/toggleNumbering';

import {
ContentModelDocument,
ContentModelFormatter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { getListTypeStyle } from './getListTypeStyle';
import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-dom';
import {
getListAnnounceData,
setListType,
setModelListStartNumber,
setModelListStyle,
} from 'roosterjs-content-model-api';
import type {
ContentModelListItem,
FormatContentModelContext,
ReadonlyContentModelDocument,
ShallowMutableContentModelParagraph,
Expand All @@ -26,6 +29,7 @@ export function keyboardListTrigger(
const { listType, styleType, index } = listStyleType;
triggerList(model, listType, styleType, index);
context.canUndoByBackspace = true;
setAnnounceData(model, context);

return true;
}
Expand All @@ -48,9 +52,23 @@ const triggerList = (
isOrderedList
? {
orderedStyleType: styleType,
applyListStyleFromLevel: false,
}
: {
unorderedStyleType: styleType,
applyListStyleFromLevel: false,
}
);
};
function setAnnounceData(model: ReadonlyContentModelDocument, context: FormatContentModelContext) {
const [paragraphOrListItems] = getOperationalBlocks<ContentModelListItem>(
model,
['ListItem'],
[] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any
);

if (paragraphOrListItems && isBlockGroupOfType(paragraphOrListItems.block, 'ListItem')) {
const { path, block } = paragraphOrListItems;
context.announceData = getListAnnounceData([block, ...path]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('keyboardListTrigger', () => {
context: FormatContentModelContext,
expectedResult: boolean,
shouldSearchForBullet: boolean = true,
shouldSearchForNumbering: boolean = true
shouldSearchForNumbering: boolean = true,
expectedContext?: any
) {
const result = keyboardListTrigger(
model,
Expand All @@ -22,6 +23,9 @@ describe('keyboardListTrigger', () => {
shouldSearchForNumbering
);
expect(result).toBe(expectedResult);
if (expectedContext) {
expect(context).toEqual(expectedContext);
}
}

it('trigger numbering list', () => {
Expand Down Expand Up @@ -49,7 +53,16 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{ canUndoByBackspace: true } as any,
true
true /* expectedResult */,
undefined /* shouldSearchForBullet */,
undefined /* shouldSearchForNumbering */,
{
canUndoByBackspace: true,
announceData: {
defaultStrings: 'announceListItemNumbering',
formatStrings: ['1'],
},
}
);
});

Expand Down Expand Up @@ -118,7 +131,13 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{ canUndoByBackspace: true } as any,
true
true,
undefined /* shouldSearchForBullet */,
undefined /* shouldSearchForNumbering */,
{
canUndoByBackspace: true,
announceData: { defaultStrings: 'announceListItemNumbering', formatStrings: ['2'] },
}
);
});

Expand Down Expand Up @@ -147,7 +166,10 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{ canUndoByBackspace: true } as any,
false
false,
undefined /* shouldSearchForBullet */,
undefined /* shouldSearchForNumbering */,
{ canUndoByBackspace: true }
);
});

Expand Down Expand Up @@ -176,7 +198,13 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{ canUndoByBackspace: true } as any,
true
true,
undefined /* shouldSearchForBullet */,
undefined /* shouldSearchForNumbering */,
{
canUndoByBackspace: true,
announceData: { defaultStrings: 'announceListItemBullet' },
}
);
});

Expand Down Expand Up @@ -205,7 +233,10 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{} as any,
false
false,
undefined,
undefined,
{}
);
});

Expand Down Expand Up @@ -384,7 +415,16 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{ canUndoByBackspace: true } as any,
true
true,
undefined /* shouldSearchForBullet */,
undefined /* shouldSearchForNumbering */,
{
canUndoByBackspace: true,
announceData: {
defaultStrings: 'announceListItemNumbering',
formatStrings: ['3'],
},
}
);
});

Expand Down Expand Up @@ -493,7 +533,13 @@ describe('keyboardListTrigger', () => {
},
paragraph,
{ canUndoByBackspace: true } as any,
true
true,
undefined /* shouldSearchForBullet */,
undefined /* shouldSearchForNumbering */,
{
canUndoByBackspace: true,
announceData: { defaultStrings: 'announceListItemNumbering', formatStrings: ['A'] },
}
);
});
});
Loading