From a7d2d3205547b6017978c3fa9df3ee1ba26b345a Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Thu, 1 Jun 2023 15:04:34 +0800 Subject: [PATCH] fix: unable to delete node on the mobile platform --- example/lib/pages/simple_editor.dart | 3 +-- .../ime/delta_input_on_delete_impl.dart | 20 ++----------------- .../backspace_command.dart | 5 +---- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/example/lib/pages/simple_editor.dart b/example/lib/pages/simple_editor.dart index 3cdecf70b..dfcdc78c8 100644 --- a/example/lib/pages/simple_editor.dart +++ b/example/lib/pages/simple_editor.dart @@ -86,11 +86,10 @@ class SimpleEditor extends StatelessWidget { EditorState editorState, ScrollController? scrollController, ) { - return AppFlowyEditor.custom( + return AppFlowyEditor.standard( editorStyle: const EditorStyle.mobile(), editorState: editorState, scrollController: scrollController, - blockComponentBuilders: standardBlockComponentBuilderMap, ); } diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart index 832be8a3d..930dc1520 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart @@ -12,22 +12,6 @@ Future onDelete( return; } - // single line - if (selection.isSingle) { - final node = editorState.getNodeAtPath(selection.end.path); - final delta = node?.delta; - if (node == null || delta == null) { - return; - } - - final transaction = editorState.transaction - ..deleteText( - node, - deletion.deletedRange.start, - deletion.textDeleted.length, - ); - return editorState.apply(transaction); - } else { - throw UnimplementedError(); - } + // use backspace command instead. + backspaceCommand.execute(editorState); } diff --git a/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/backspace_command.dart b/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/backspace_command.dart index 6611fba51..f4f1e30ce 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/backspace_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/backspace_command.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; /// - support /// - desktop /// - web +/// - mobile /// final CommandShortcutEvent backspaceCommand = CommandShortcutEvent( key: 'backspace', @@ -111,10 +112,6 @@ CommandShortcutEventHandler _deleteLeftSentenceCommandHandler = (editorState) { }; CommandShortcutEventHandler _backspaceCommandHandler = (editorState) { - if (PlatformExtension.isMobile) { - assert(false, 'backspaceCommand is not supported on mobile platform.'); - return KeyEventResult.ignored; - } final selection = editorState.selection; if (selection == null) { return KeyEventResult.ignored;