Skip to content

Fix: Infinite loop when listen to FocusNode in read-only mode #2488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- 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).
- Remove unicode from `QuillText` element that causes weird caret behavior on empty lines [#2453](https://github.com/singerdmx/flutter-quill/pull/2453).
- Focus and open context menu on right click if unfocused [#2477](https://github.com/singerdmx/flutter-quill/pull/2477).
- Update QuillController `length` extension method deprecation message [#2483](https://github.com/singerdmx/flutter-quill/pull/2483).
Expand Down
22 changes: 12 additions & 10 deletions lib/src/editor/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,6 @@ class QuillRawEditorState extends EditorState
_clipboardStatus!.addListener(_onChangedClipboardStatus);
}

controller.addListener(_didChangeTextEditingValueListener);

_scrollController = widget.config.scrollController;
_scrollController.addListener(_updateSelectionOverlayForScroll);

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

// listen to composing range changes
composingRange.addListener(_onComposingRangeChanged);

if (isKeyboardOS) {
_keyboardVisible = true;
} else if (!kIsWeb && isFlutterTest) {
Expand All @@ -858,8 +853,13 @@ class QuillRawEditorState extends EditorState
});
}

// Focus
widget.config.focusNode.addListener(_handleFocusChanged);
if (!widget.config.readOnly) {
controller.addListener(_didChangeTextEditingValueListener);
// listen to composing range changes
composingRange.addListener(_onComposingRangeChanged);
// Focus
widget.config.focusNode.addListener(_handleFocusChanged);
}
}

// KeyboardVisibilityController only checks for keyboards that
Expand Down Expand Up @@ -965,10 +965,12 @@ class QuillRawEditorState extends EditorState
assert(!hasConnection);
_selectionOverlay?.dispose();
_selectionOverlay = null;
controller.removeListener(_didChangeTextEditingValueListener);
widget.config.focusNode.removeListener(_handleFocusChanged);
if (!widget.config.readOnly) {
controller.removeListener(_didChangeTextEditingValueListener);
widget.config.focusNode.removeListener(_handleFocusChanged);
composingRange.removeListener(_onComposingRangeChanged);
}
_cursorCont.dispose();
composingRange.removeListener(_onComposingRangeChanged);
if (_clipboardStatus != null) {
_clipboardStatus!
..removeListener(_onChangedClipboardStatus)
Expand Down
Loading