Keep cursor position on checkbox tap

pull/834/head
Pavel Kozlovskiy 3 years ago
parent bad872c347
commit 77033bd6fc
  1. 6
      lib/src/widgets/raw_editor.dart

@ -411,6 +411,8 @@ class RawEditorState extends EditorState
void _handleCheckboxTap(int offset, bool value) {
if (!widget.readOnly) {
_disableScrollControllerAnimateOnce = true;
widget.controller.ignoreFocusOnTextChange = true;
final currentSelection = widget.controller.selection.copyWith();
final attribute = value ? Attribute.checked : Attribute.unchecked;
widget.controller.formatText(offset, 0, attribute);
@ -424,8 +426,8 @@ class RawEditorState extends EditorState
// Go back from offset 0 to current selection
SchedulerBinding.instance.addPostFrameCallback((_) {
widget.controller.updateSelection(
TextSelection.collapsed(offset: offset), ChangeSource.LOCAL);
widget.controller.ignoreFocusOnTextChange = false;
widget.controller.updateSelection(currentSelection, ChangeSource.LOCAL);
});
}
}

Loading…
Cancel
Save