mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: fix something wrong when deleting the text nodes
This commit is contained in:
parent
af2f6a03d5
commit
585c9f8753
@ -183,7 +183,7 @@ class TextNode extends Node {
|
||||
super(children: children ?? LinkedList(), attributes: attributes ?? {});
|
||||
|
||||
TextNode.empty()
|
||||
: _delta = Delta([TextInsert(' ')]),
|
||||
: _delta = Delta([TextInsert('')]),
|
||||
super(
|
||||
type: 'text',
|
||||
children: LinkedList(),
|
||||
|
@ -46,8 +46,14 @@ FlowyKeyEventHandler deleteTextHandler = (editorState, event) {
|
||||
if (textNode.previous is TextNode) {
|
||||
final previous = textNode.previous as TextNode;
|
||||
transactionBuilder
|
||||
..mergeText(previous, textNode)
|
||||
..deleteNode(textNode)
|
||||
..mergeText(previous, textNode);
|
||||
..afterSelection = Selection.collapsed(
|
||||
Position(
|
||||
path: previous.path,
|
||||
offset: previous.toRawString().length,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ import 'package:flowy_editor/service/keyboard_service.dart';
|
||||
/// 2. Single selection and the selected node is [TextNode]
|
||||
/// 2.1 split the node into two nodes with style
|
||||
/// 2.2 or insert a empty text node before.
|
||||
FlowyKeyEventHandler enterWithoutShiftHandler = (editorState, event) {
|
||||
FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler =
|
||||
(editorState, event) {
|
||||
if (event.logicalKey != LogicalKeyboardKey.enter || event.isShiftPressed) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
@ -87,11 +88,6 @@ FlowyKeyEventHandler enterWithoutShiftHandler = (editorState, event) {
|
||||
Position(path: textNode.path.next, offset: 0),
|
||||
);
|
||||
TransactionBuilder(editorState)
|
||||
..deleteText(
|
||||
textNode,
|
||||
selection.start.offset,
|
||||
textNode.toRawString().length,
|
||||
)
|
||||
..insertNode(
|
||||
textNode.path.next,
|
||||
textNode.copyWith(
|
||||
@ -99,6 +95,11 @@ FlowyKeyEventHandler enterWithoutShiftHandler = (editorState, event) {
|
||||
delta: textNode.delta.slice(selection.end.offset),
|
||||
),
|
||||
)
|
||||
..deleteText(
|
||||
textNode,
|
||||
selection.start.offset,
|
||||
textNode.toRawString().length - selection.start.offset,
|
||||
)
|
||||
..afterSelection = afterSelection
|
||||
..commit();
|
||||
return KeyEventResult.handled;
|
||||
|
Loading…
Reference in New Issue
Block a user