Skip to content

Commit 8d63996

Browse files
chaosuechaos
authored andcommitted
fix: unpredictable endless loop of '_handleFocusChanged' in the phase of page route changing when editor is set to readonly. (singerdmx#2488)
Co-authored-by: chaos <chaos@veigit.com>
1 parent eb91d24 commit 8d63996

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414

15+
- Remove unnecessary content change listeners in read-only mode to avoid triggering infinite loops of **FocusNode** callbacks [#2488](https://github.com/singerdmx/flutter-quill/pull/2488).
1516
- Remove unicode from `QuillText` element that causes weird caret behavior on empty lines [#2453](https://github.com/singerdmx/flutter-quill/pull/2453).
1617
- Focus and open context menu on right click if unfocused [#2477](https://github.com/singerdmx/flutter-quill/pull/2477).
1718
- Update QuillController `length` extension method deprecation message [#2483](https://github.com/singerdmx/flutter-quill/pull/2483).

lib/src/editor/raw_editor/raw_editor_state.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,6 @@ class QuillRawEditorState extends EditorState
813813
_clipboardStatus!.addListener(_onChangedClipboardStatus);
814814
}
815815

816-
controller.addListener(_didChangeTextEditingValueListener);
817-
818816
_scrollController = widget.config.scrollController;
819817
_scrollController.addListener(_updateSelectionOverlayForScroll);
820818

@@ -828,9 +826,6 @@ class QuillRawEditorState extends EditorState
828826
_floatingCursorResetController = AnimationController(vsync: this);
829827
_floatingCursorResetController.addListener(onFloatingCursorResetTick);
830828

831-
// listen to composing range changes
832-
composingRange.addListener(_onComposingRangeChanged);
833-
834829
if (isKeyboardOS) {
835830
_keyboardVisible = true;
836831
} else if (!kIsWeb && isFlutterTest) {
@@ -857,8 +852,13 @@ class QuillRawEditorState extends EditorState
857852
});
858853
}
859854

860-
// Focus
861-
widget.config.focusNode.addListener(_handleFocusChanged);
855+
if (!widget.config.readOnly) {
856+
controller.addListener(_didChangeTextEditingValueListener);
857+
// listen to composing range changes
858+
composingRange.addListener(_onComposingRangeChanged);
859+
// Focus
860+
widget.config.focusNode.addListener(_handleFocusChanged);
861+
}
862862
}
863863

864864
// KeyboardVisibilityController only checks for keyboards that
@@ -964,10 +964,12 @@ class QuillRawEditorState extends EditorState
964964
assert(!hasConnection);
965965
_selectionOverlay?.dispose();
966966
_selectionOverlay = null;
967-
controller.removeListener(_didChangeTextEditingValueListener);
968-
widget.config.focusNode.removeListener(_handleFocusChanged);
967+
if (!widget.config.readOnly) {
968+
controller.removeListener(_didChangeTextEditingValueListener);
969+
widget.config.focusNode.removeListener(_handleFocusChanged);
970+
composingRange.removeListener(_onComposingRangeChanged);
971+
}
969972
_cursorCont.dispose();
970-
composingRange.removeListener(_onComposingRangeChanged);
971973
if (_clipboardStatus != null) {
972974
_clipboardStatus!
973975
..removeListener(_onChangedClipboardStatus)

0 commit comments

Comments
 (0)