feat: refresh number list when delete multiple lines

This commit is contained in:
Vincent Chan 2022-09-09 15:13:21 +08:00
parent 0310b92723
commit 2775737260
2 changed files with 28 additions and 4 deletions

View File

@ -93,9 +93,19 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
}
}
} else {
if (textNodes.isNotEmpty) {
_deleteTextNodes(transactionBuilder, textNodes, selection);
if (textNodes.isEmpty) {
return KeyEventResult.handled;
}
final startPosition = selection.start;
final nodeAtStart = editorState.document.nodeAtPath(startPosition.path)!;
_deleteTextNodes(transactionBuilder, textNodes, selection);
transactionBuilder.commit();
if (nodeAtStart is TextNode && nodeAtStart.subtype == StyleKey.numberList) {
makeFollowingNodesIncremental(
editorState, startPosition.path, transactionBuilder.afterSelection!);
}
return KeyEventResult.handled;
}
if (transactionBuilder.operations.isNotEmpty) {
@ -156,11 +166,18 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
);
}
}
transactionBuilder.commit();
} else {
final startPosition = selection.start;
final nodeAtStart = editorState.document.nodeAtPath(startPosition.path)!;
_deleteTextNodes(transactionBuilder, textNodes, selection);
}
transactionBuilder.commit();
transactionBuilder.commit();
if (nodeAtStart is TextNode && nodeAtStart.subtype == StyleKey.numberList) {
makeFollowingNodesIncremental(
editorState, startPosition.path, transactionBuilder.afterSelection!);
}
}
return KeyEventResult.handled;
}

View File

@ -37,6 +37,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
// Multiple selection
if (!selection.isSingle) {
final startNode = editorState.document.nodeAtPath(selection.start.path)!;
final length = textNodes.length;
final List<TextNode> subTextNodes =
length >= 3 ? textNodes.sublist(1, textNodes.length - 1) : [];
@ -57,6 +58,12 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
)
..afterSelection = afterSelection
..commit();
if (startNode is TextNode && startNode.subtype == StyleKey.numberList) {
makeFollowingNodesIncremental(
editorState, selection.start.path, afterSelection);
}
return KeyEventResult.handled;
}