mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: handle number list on delete event
This commit is contained in:
parent
cfdd891991
commit
ee0f3d3227
@ -10,7 +10,6 @@ import 'package:appflowy_editor/src/document/text_delta.dart';
|
||||
import 'package:appflowy_editor/src/editor_state.dart';
|
||||
import 'package:appflowy_editor/src/operation/operation.dart';
|
||||
import 'package:appflowy_editor/src/operation/transaction.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
/// A [TransactionBuilder] is used to build the transaction from the state.
|
||||
/// It will save a snapshot of the cursor selection state automatically.
|
||||
|
@ -181,16 +181,16 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
|
||||
final transactionBuilder = TransactionBuilder(editorState);
|
||||
if (textNodes.length == 1) {
|
||||
final textNode = textNodes.first;
|
||||
// The cursor is at the end of the line,
|
||||
// merge next line into this line.
|
||||
if (selection.start.offset >= textNode.delta.length) {
|
||||
final nextNode = textNode.next;
|
||||
if (nextNode == null) {
|
||||
return KeyEventResult.ignored;
|
||||
return _mergeNextLineIntoThisLine(
|
||||
editorState,
|
||||
textNode,
|
||||
transactionBuilder,
|
||||
selection,
|
||||
);
|
||||
}
|
||||
if (nextNode is TextNode) {
|
||||
transactionBuilder.mergeText(textNode, nextNode);
|
||||
}
|
||||
transactionBuilder.deleteNode(nextNode);
|
||||
} else {
|
||||
final index = textNode.delta.nextRunePosition(selection.start.offset);
|
||||
if (selection.isCollapsed) {
|
||||
transactionBuilder.deleteText(
|
||||
@ -205,7 +205,6 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
|
||||
selection.end.offset - selection.start.offset,
|
||||
);
|
||||
}
|
||||
}
|
||||
transactionBuilder.commit();
|
||||
} else {
|
||||
final startPosition = selection.start;
|
||||
@ -222,6 +221,28 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
KeyEventResult _mergeNextLineIntoThisLine(
|
||||
EditorState editorState,
|
||||
TextNode textNode,
|
||||
TransactionBuilder transactionBuilder,
|
||||
Selection selection) {
|
||||
final nextNode = textNode.next;
|
||||
if (nextNode == null) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
if (nextNode is TextNode) {
|
||||
transactionBuilder.mergeText(textNode, nextNode);
|
||||
}
|
||||
transactionBuilder.deleteNode(nextNode);
|
||||
transactionBuilder.commit();
|
||||
|
||||
if (textNode.subtype == StyleKey.numberList) {
|
||||
makeFollowingNodesIncremental(editorState, textNode.path, selection);
|
||||
}
|
||||
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
void _deleteTextNodes(TransactionBuilder transactionBuilder,
|
||||
List<TextNode> textNodes, Selection selection) {
|
||||
final first = textNodes.first;
|
||||
|
Loading…
x
Reference in New Issue
Block a user