fix(markdown-widget): apply list item style on each block in a selection (#5676)

This commit is contained in:
Trang Le
2021-08-04 21:54:52 +07:00
committed by GitHub
parent d930fb422a
commit 04e53054ce
2 changed files with 59 additions and 8 deletions

View File

@ -152,7 +152,7 @@ function ListPlugin({ defaultType, unorderedListType, orderedListType }) {
if (!LIST_TYPES.includes(type)) {
throw Error(`${type} is not a valid list type, must be one of: ${LIST_TYPES}`);
}
const { startBlock } = editor.value;
const { startBlock, blocks } = editor.value;
const target = editor.getBlockContainer();
switch (get(target, 'type')) {
@ -191,7 +191,18 @@ function ListPlugin({ defaultType, unorderedListType, orderedListType }) {
}
default: {
editor.wrapInList(type);
if (blocks.size > 1) {
const listItems = blocks.map(block =>
Block.create({ type: 'list-item', nodes: [block] }),
);
const listBlock = Block.create({ type, nodes: listItems });
editor
.delete()
.replaceNodeByKey(startBlock.key, listBlock)
.moveToRangeOfNode(listBlock);
} else {
editor.wrapInList(type);
}
break;
}
}