Skip to content

Commit

Permalink
fix(list): cannot change a numbered list that includes an inline box …
Browse files Browse the repository at this point in the history
…to another list
  • Loading branch information
luolonghao committed May 17, 2024
1 parent 63d359e commit 77426bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/operations/set-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function setBlocks(range: Range, value: string | KeyValue): void {
return;
}
if (range.isCollapsed) {
if (range.isBox) {
const boxNode = range.commonAncestor.closest('lake-box');
if (boxNode.isBlockBox) {
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default (editor: Editor) => {
}
}
editor.history.save();
editor.selection.sync();
},
});
editor.container.on('click', event => {
Expand Down
21 changes: 21 additions & 0 deletions tests/plugins/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { testPlugin } from '../utils';

// const imageUrl = '../assets/images/heaven-lake-256.png';
const imageBoxValue = 'eyJ1cmwiOiIuLi9hc3NldHMvaW1hZ2VzL2hlYXZlbi1sYWtlLTI1Ni5wbmciLCJzdGF0dXMiOiJkb25lIn0=';

describe('plugins / list', () => {

it('should change a paragraph to a numbered list', () => {
Expand Down Expand Up @@ -92,6 +95,24 @@ describe('plugins / list', () => {
);
});

it('should change a numbered list that includes an inline box to a bulleted list', () => {
const content = `
<ol><li>foo<lake-box type="inline" name="image" value="${imageBoxValue}" focus="end"></lake-box></li></ol>
<p>bar</p>
`;
const output = `
<ul><li>foo<lake-box type="inline" name="image" value="${imageBoxValue}" focus="end"></lake-box></li></ul>
<p>bar</p>
`;
testPlugin(
content,
output,
editor => {
editor.command.execute('list', 'bulleted');
},
);
});

it('should change a numbered list to a checklist', () => {
const content = `
<ol><li>foo<focus /></li></ol>
Expand Down

0 comments on commit 77426bc

Please sign in to comment.