From 7bd494a3d7ccdbde45a5f6e47ee79c4d7e6f1732 Mon Sep 17 00:00:00 2001 From: X Code Date: Sun, 30 Jan 2022 22:14:50 -0800 Subject: [PATCH] Fix cursor position changes when checking/unchecking the checkbox --- lib/src/widgets/raw_editor.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index 22833768..c2df6395 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -404,6 +404,7 @@ class RawEditorState extends EditorState /// by changing its attribute according to [value]. void _handleCheckboxTap(int offset, bool value) { if (!widget.readOnly) { + _disableScrollControllerAnimateOnce = true; widget.controller.formatText( offset, 0, value ? Attribute.checked : Attribute.unchecked); } @@ -759,6 +760,12 @@ class RawEditorState extends EditorState bool _showCaretOnScreenScheduled = false; + // This is a workaround for checkbox tapping issue + // https://github.com/singerdmx/flutter-quill/issues/619 + // We cannot treat {"list": "checked"} and {"list": "unchecked"} as + // block of the same style + bool _disableScrollControllerAnimateOnce = false; + void _showCaretOnScreen() { if (!widget.showCursor || _showCaretOnScreenScheduled) { return; @@ -785,6 +792,10 @@ class RawEditorState extends EditorState ); if (offset != null) { + if (_disableScrollControllerAnimateOnce) { + _disableScrollControllerAnimateOnce = false; + return; + } _scrollController.animateTo( math.min(offset, _scrollController.position.maxScrollExtent), duration: const Duration(milliseconds: 100),