Fix cursor position changes when checking/unchecking the checkbox

pull/633/head
X Code 3 years ago
parent 3c7fcb3c66
commit 7bd494a3d7
  1. 11
      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),

Loading…
Cancel
Save