Skip to content

Commit 7262be7

Browse files
chaosuechaos
and
chaos
authored
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 <[email protected]>
1 parent f376f72 commit 7262be7

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
@@ -814,8 +814,6 @@ class QuillRawEditorState extends EditorState
814814
_clipboardStatus!.addListener(_onChangedClipboardStatus);
815815
}
816816

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

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

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

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

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

0 commit comments

Comments
 (0)