diff --git a/packages/fleather/lib/src/widgets/controller.dart b/packages/fleather/lib/src/widgets/controller.dart index 0d738614..05da9df9 100644 --- a/packages/fleather/lib/src/widgets/controller.dart +++ b/packages/fleather/lib/src/widgets/controller.dart @@ -21,10 +21,13 @@ List _toggleableStyleKeys = [ ]; class FleatherController extends ChangeNotifier { - FleatherController({ParchmentDocument? document, AutoFormats? autoFormats}) + FleatherController( + {ParchmentDocument? document, + AutoFormats? autoFormats, + this.skipScrollOnToggleLeading = false}) : _document = document ?? ParchmentDocument(), _history = HistoryStack.doc(document), - _autoFormats = autoFormats ?? AutoFormats.fallback(), + _autoFormats = autoFormats ?? AutoFormats.fallback(), _selection = const TextSelection.collapsed(offset: 0) { _throttledPush = _throttle( duration: throttleDuration, @@ -43,6 +46,10 @@ class FleatherController extends ChangeNotifier { late _Throttled _throttledPush; Timer? _throttleTimer; + // skipScroll if formatText but just for toggle leading checkbox + final bool skipScrollOnToggleLeading; + bool skipScroll = false; + // The auto format handler final AutoFormats _autoFormats; @@ -202,7 +209,8 @@ class FleatherController extends ChangeNotifier { return true; } - void formatText(int index, int length, ParchmentAttribute attribute) { + void formatText(int index, int length, ParchmentAttribute attribute, + {bool withoutScroll = false}) { final change = document.format(index, length, attribute); // _lastChangeSource = ChangeSource.local; const source = ChangeSource.local; @@ -223,7 +231,9 @@ class FleatherController extends ChangeNotifier { _updateSelectionSilent(adjustedSelection, source: source); } _updateHistory(); + skipScroll = withoutScroll; notifyListeners(); + skipScroll = false; } /// Formats current selection with [attribute]. diff --git a/packages/fleather/lib/src/widgets/editable_text_block.dart b/packages/fleather/lib/src/widgets/editable_text_block.dart index a4bb4f04..78e96f85 100644 --- a/packages/fleather/lib/src/widgets/editable_text_block.dart +++ b/packages/fleather/lib/src/widgets/editable_text_block.dart @@ -256,7 +256,8 @@ class EditableTextBlock extends StatelessWidget { void _toggle(LineNode node, bool checked) { final attr = checked ? ParchmentAttribute.checked : ParchmentAttribute.checked.unset; - controller.formatText(node.documentOffset, 0, attr); + controller.formatText(node.documentOffset, 0, attr, + withoutScroll: controller.skipScrollOnToggleLeading); } } diff --git a/packages/fleather/lib/src/widgets/editor.dart b/packages/fleather/lib/src/widgets/editor.dart index 43379301..ab307be8 100644 --- a/packages/fleather/lib/src/widgets/editor.dart +++ b/packages/fleather/lib/src/widgets/editor.dart @@ -1594,6 +1594,10 @@ class RawEditorState extends EditorState return; } + if (widget.controller.skipScroll) { + return; + } + _showCaretOnScreenScheduled = true; SchedulerBinding.instance.addPostFrameCallback((Duration _) { _showCaretOnScreenScheduled = false;