Skip to content

Commit 739f4ee

Browse files
committed
fix: handle unwrapping inline nodes in lists
1 parent 3a0a701 commit 739f4ee

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

packages/decap-cms-widget-markdown/src/MarkdownControl/plugins/blocks/transforms/unwrapIfCursorAtStart.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ import lowestMatchedAncestor from '../../matchers/lowestMatchedAncestor';
55
function unwrapIfCursorAtStart(editor, mergeWithPrevious = false) {
66
if (editor.selection.anchor.offset !== 0) return false;
77

8-
const node = Editor.above(editor, lowestMatchedAncestor(editor, 'non-default'));
8+
let [node, path] = Editor.above(editor, lowestMatchedAncestor(editor, 'non-default'));
99

10-
if (node[1].length == 0) return false;
10+
if (path.length == 0) return false;
1111

12-
const isHeading = `${node[0].type}`.startsWith('heading-');
12+
const isHeading = `${node.type}`.startsWith('heading-');
1313
if (isHeading) {
1414
Transforms.setNodes(editor, { type: 'paragraph' });
1515
return false;
1616
}
1717

18+
const isBlock = Editor.isBlock(editor, node);
19+
const [parentBlock, parentBlockPath] = Editor.above(editor, lowestMatchedAncestor(editor, 'block'));
20+
if (!isBlock) {
21+
if (!Editor.isStart(editor, path, parentBlockPath)) {
22+
return false;
23+
}
24+
25+
[node, path] = [parentBlock, parentBlockPath];
26+
}
27+
1828
Editor.withoutNormalizing(editor, () => {
19-
Transforms.unwrapNodes(editor, { match: n => n.type === node[0].type, split: true });
29+
Transforms.unwrapNodes(editor, { match: n => n.type === node.type, split: true });
2030

2131
if (mergeWithPrevious) {
2232
Transforms.mergeNodes(editor);

0 commit comments

Comments
 (0)