Skip to content

Commit

Permalink
feature/bug? enable skip scroll while tap checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdykme committed Aug 11, 2024
1 parent e7c7a9a commit bd834ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/fleather/lib/src/widgets/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ List<String> _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,
Expand All @@ -43,6 +46,10 @@ class FleatherController extends ChangeNotifier {
late _Throttled<Delta> _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;

Expand Down Expand Up @@ -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;
Expand All @@ -223,7 +231,9 @@ class FleatherController extends ChangeNotifier {
_updateSelectionSilent(adjustedSelection, source: source);
}
_updateHistory();
skipScroll = withoutScroll;
notifyListeners();
skipScroll = false;
}

/// Formats current selection with [attribute].
Expand Down
3 changes: 2 additions & 1 deletion packages/fleather/lib/src/widgets/editable_text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/fleather/lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,10 @@ class RawEditorState extends EditorState
return;
}

if (widget.controller.skipScroll) {
return;
}

_showCaretOnScreenScheduled = true;
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
_showCaretOnScreenScheduled = false;
Expand Down

0 comments on commit bd834ea

Please sign in to comment.