AppFlowy-IO / appflowy-editor

A highly customizable rich-text editor for Flutter. The AppFlowy Editor project for AppFlowy and beyond.
https://pub.dev/packages/appflowy_editor
Other
473 stars 201 forks source link

[Bug] Deleting the last empty entry crashes the Editor #948

Open saif-ellafi opened 3 weeks ago

saif-ellafi commented 3 weeks ago

Bug Description

In my AppFlowyEditor, if I have an empty entry, and I press delete (i.e. delete the empty line), then the Editor crashes. The Editor also crashes if the editor is fully blank. In MacOS, I am allowed to delete an empty line by pressing backspace. This also happens when I delete a Table and the table was the last thing I had in the Editor.

The MacOS version issue may be the one fixed here: https://github.com/AppFlowy-IO/appflowy-editor/issues/927 - not sure about the deleting table version of this issue

════════ Exception caught by gesture ═══════════════════════════════════════════
Invalid argument(s): 0
════════════════════════════════════════════════════════════════════════════════
Restarted application in 1,761ms.
flutter: unhandled element <style/>; Picture key: Svg loader
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (start): Invalid value: Only valid value is 0: -1
#0      RangeError.checkValidRange (dart:core/errors.dart:360:7)
errors.dart:360
#1      _StringBase.substring (dart:core-patch/string_patch.dart:418:27)
string_patch.dart:418
#2      TextEditingDeltaDeletion.textDeleted (package:flutter/src/services/text_editing_delta.dart:314:37)
text_editing_delta.dart:314
#3      TextEditingDeltaDeletion.debugFillProperties (package:flutter/src/services/text_editing_delta.dart:333:63)
text_editing_delta.dart:333
#4      DiagnosticableNode.builder.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:2837:17)
diagnostics.dart:2837
#5      DiagnosticableNode.builder (package:flutter/src/foundation/diagnostics.dart:2840:8)
diagnostics.dart:2840
#6      DiagnosticableNode.getProperties (package:flutter/src/foundation/diagnostics.dart:2854:105)
diagnostics.dart:2854

Even worse, if the last thing I delete is a Table, then the Editor crashes, but also the app does not resume, and needs a full app restart to use it. This is the error when the last entry fully deleted is a table:

════════ Exception caught by gesture ═══════════════════════════════════════════
The following ArgumentError was thrown while handling a gesture:
Invalid argument(s): 0

When the exception was thrown, this was the stack:
#0      int.clamp (dart:core-patch/integers.dart:280:7)
integers.dart:280
#1      EditorStateSelection._findCloseNode (package:appflowy_editor/src/editor/editor_component/service/selection/shared.dart:98:16)
shared.dart:98
#2      EditorStateSelection.getNodeInOffset (package:appflowy_editor/src/editor/editor_component/service/selection/shared.dart:41:15)
shared.dart:41
#3      _DesktopSelectionServiceWidgetState.getNodeInOffset (package:appflowy_editor/src/editor/editor_component/service/selection/desktop_selection_service.dart:156:24)
desktop_selection_service.dart:156
#4      _DesktopSelectionServiceWidgetState._onTapDown (package:appflowy_editor/src/editor/editor_component/service/selection/desktop_selection_service.dart:210:18)
desktop_selection_service.dart:210

How to Reproduce

Expected Behavior

Should not crash.

Operating System

All systems, but the "just delete" I can't reproduce on Windows, but yes on MacOS. Strange!

AppFlowy Editor Version(s)

4.0.0

Screenshots

No response

Additional Context

No response