mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: could not remove text style when pressing enter in empty text node
This commit is contained in:
parent
4223324689
commit
1391d202a9
@ -137,17 +137,16 @@ class TransactionBuilder {
|
||||
|
||||
replaceText(TextNode node, int index, int length, String content,
|
||||
[Attributes? attributes]) {
|
||||
var newAttributes = attributes;
|
||||
if (attributes == null) {
|
||||
final ops = node.delta.slice(index, index + length).operations;
|
||||
if (ops.isNotEmpty) {
|
||||
newAttributes = ops.first.attributes;
|
||||
}
|
||||
}
|
||||
textEdit(
|
||||
node,
|
||||
() => Delta().retain(index).delete(length).insert(
|
||||
content,
|
||||
attributes ??
|
||||
node.delta
|
||||
.slice(index, index + length)
|
||||
.operations
|
||||
.first
|
||||
.attributes,
|
||||
),
|
||||
() => Delta().retain(index).delete(length).insert(content, newAttributes),
|
||||
);
|
||||
afterSelection = Selection.collapsed(
|
||||
Position(
|
||||
|
@ -51,6 +51,7 @@ class StyleKey {
|
||||
];
|
||||
|
||||
static List<String> globalStyleKeys = [
|
||||
StyleKey.subtype,
|
||||
StyleKey.heading,
|
||||
StyleKey.checkbox,
|
||||
StyleKey.bulletedList,
|
||||
|
@ -67,16 +67,31 @@ FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler =
|
||||
// If selection is collapsed and position.start.offset == 0,
|
||||
// insert a empty text node before.
|
||||
if (selection.isCollapsed && selection.start.offset == 0) {
|
||||
final afterSelection = Selection.collapsed(
|
||||
Position(path: textNode.path.next, offset: 0),
|
||||
);
|
||||
TransactionBuilder(editorState)
|
||||
..insertNode(
|
||||
textNode.path,
|
||||
TextNode.empty(),
|
||||
)
|
||||
..afterSelection = afterSelection
|
||||
..commit();
|
||||
if (textNode.toRawString().isEmpty) {
|
||||
final afterSelection = Selection.collapsed(
|
||||
Position(path: textNode.path, offset: 0),
|
||||
);
|
||||
TransactionBuilder(editorState)
|
||||
..updateNode(
|
||||
textNode,
|
||||
Attributes.fromIterable(
|
||||
StyleKey.globalStyleKeys,
|
||||
value: (_) => null,
|
||||
))
|
||||
..afterSelection = afterSelection
|
||||
..commit();
|
||||
} else {
|
||||
final afterSelection = Selection.collapsed(
|
||||
Position(path: textNode.path.next, offset: 0),
|
||||
);
|
||||
TransactionBuilder(editorState)
|
||||
..insertNode(
|
||||
textNode.path,
|
||||
TextNode.empty(),
|
||||
)
|
||||
..afterSelection = afterSelection
|
||||
..commit();
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user