Merge pull request #833 from LucasXu0/fix/#832

fix: #832
This commit is contained in:
Lucas.Xu 2022-08-12 14:49:12 +08:00 committed by GitHub
commit a539630fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,12 +4,13 @@ import 'package:flutter/services.dart';
import 'package:flowy_editor/flowy_editor.dart';
KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
final selection = editorState.service.selectionService.currentSelection.value;
var selection = editorState.service.selectionService.currentSelection.value;
if (selection == null) {
return KeyEventResult.ignored;
}
final nodes = editorState.service.selectionService.currentSelectedNodes;
var nodes = editorState.service.selectionService.currentSelectedNodes;
nodes = selection.isBackward ? nodes : nodes.reversed.toList(growable: false);
selection = selection.isBackward ? selection : selection.reversed;
// make sure all nodes is [TextNode].
final textNodes = nodes.whereType<TextNode>().toList();
if (textNodes.length != nodes.length) {
@ -20,7 +21,7 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
if (textNodes.length == 1) {
final textNode = textNodes.first;
final index = textNode.delta.prevRunePosition(selection.start.offset);
if (index < 0) {
if (index < 0 && selection.isCollapsed) {
// 1. style
if (textNode.subtype != null) {
transactionBuilder