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:
@ -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/editor_state.dart';
|
||||||
import 'package:appflowy_editor/src/operation/operation.dart';
|
import 'package:appflowy_editor/src/operation/operation.dart';
|
||||||
import 'package:appflowy_editor/src/operation/transaction.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.
|
/// A [TransactionBuilder] is used to build the transaction from the state.
|
||||||
/// It will save a snapshot of the cursor selection state automatically.
|
/// 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);
|
final transactionBuilder = TransactionBuilder(editorState);
|
||||||
if (textNodes.length == 1) {
|
if (textNodes.length == 1) {
|
||||||
final textNode = textNodes.first;
|
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) {
|
if (selection.start.offset >= textNode.delta.length) {
|
||||||
final nextNode = textNode.next;
|
return _mergeNextLineIntoThisLine(
|
||||||
if (nextNode == null) {
|
editorState,
|
||||||
return KeyEventResult.ignored;
|
textNode,
|
||||||
|
transactionBuilder,
|
||||||
|
selection,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (nextNode is TextNode) {
|
|
||||||
transactionBuilder.mergeText(textNode, nextNode);
|
|
||||||
}
|
|
||||||
transactionBuilder.deleteNode(nextNode);
|
|
||||||
} else {
|
|
||||||
final index = textNode.delta.nextRunePosition(selection.start.offset);
|
final index = textNode.delta.nextRunePosition(selection.start.offset);
|
||||||
if (selection.isCollapsed) {
|
if (selection.isCollapsed) {
|
||||||
transactionBuilder.deleteText(
|
transactionBuilder.deleteText(
|
||||||
@ -205,7 +205,6 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
|
|||||||
selection.end.offset - selection.start.offset,
|
selection.end.offset - selection.start.offset,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
transactionBuilder.commit();
|
transactionBuilder.commit();
|
||||||
} else {
|
} else {
|
||||||
final startPosition = selection.start;
|
final startPosition = selection.start;
|
||||||
@ -222,6 +221,28 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
|
|||||||
return KeyEventResult.handled;
|
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,
|
void _deleteTextNodes(TransactionBuilder transactionBuilder,
|
||||||
List<TextNode> textNodes, Selection selection) {
|
List<TextNode> textNodes, Selection selection) {
|
||||||
final first = textNodes.first;
|
final first = textNodes.first;
|
||||||
|
Reference in New Issue
Block a user