Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi committed Jul 11, 2024
2 parents aec6607 + 34b7567 commit 12673f7
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 20 deletions.
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,
})
);
}
} 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'] },
}
);
});
});

0 comments on commit 12673f7

Please sign in to comment.