Skip to content

Commit a96cead

Browse files
committed
fix a slate list edit crash
1 parent 4b00a05 commit a96cead

File tree

1 file changed

+13
-9
lines changed
  • src/packages/frontend/editors/slate/format

1 file changed

+13
-9
lines changed

src/packages/frontend/editors/slate/format/indent.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function unindentListItem(editor: Editor): boolean {
104104
export function getNode(
105105
editor,
106106
match,
107-
at: Location | undefined = undefined
107+
at: Location | undefined = undefined,
108108
): [Element, number[]] | [undefined, undefined] {
109109
if (at != null) {
110110
// First try the node at *specific* given position.
@@ -120,19 +120,23 @@ export function getNode(
120120
// no such element, so try search below...
121121
}
122122
}
123-
for (const elt of Editor.nodes(editor, {
124-
match: (node, path) => Element.isElement(node) && match(node, path),
125-
mode: "lowest",
126-
at,
127-
})) {
128-
return [elt[0] as Element, elt[1]];
123+
try {
124+
for (const elt of Editor.nodes(editor, {
125+
match: (node, path) => Element.isElement(node) && match(node, path),
126+
mode: "lowest",
127+
at,
128+
})) {
129+
return [elt[0] as Element, elt[1]];
130+
}
131+
} catch (_err) {
132+
// no such element
129133
}
130134
return [undefined, undefined];
131135
}
132136

133137
export function indentListItem(
134138
editor: Editor,
135-
at: Location | undefined = undefined
139+
at: Location | undefined = undefined,
136140
): boolean {
137141
const [item, path] = getNode(editor, (node) => node.type == "list_item", at);
138142
if (item == null || path == null) {
@@ -188,7 +192,7 @@ export function indentListItem(
188192
Transforms.wrapNodes(
189193
editor,
190194
{ type: list.type, tight: true, children: [] },
191-
{ at: to }
195+
{ at: to },
192196
);
193197
});
194198
} catch (err) {

0 commit comments

Comments
 (0)