Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai committed Feb 19, 2021
1 parent b00c26c commit 8868819
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/flutter/lib/src/material/selectable_text.dart
Expand Up @@ -494,17 +494,21 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
});
}

TextSelection? _lastSeenTextSelection;

void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
if (willShowSelectionHandles != _showSelectionHandles) {
setState(() {
_showSelectionHandles = willShowSelectionHandles;
});
}

if (widget.onSelectionChanged != null) {
// TODO(chunhtai): The selection may be the same. We should remove this
// check once this is fixed https://github.com/flutter/flutter/issues/76349.
if (widget.onSelectionChanged != null && _lastSeenTextSelection != selection) {
widget.onSelectionChanged!(selection, cause);
}
_lastSeenTextSelection = selection;

switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
Expand Down
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/widgets/editable_text.dart
Expand Up @@ -2138,7 +2138,9 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_selectionOverlay!.handlesVisible = widget.showSelectionHandles;
_selectionOverlay!.showHandles();
}

// TODO(chunhtai): we should make sure selection actually changed before
// we call the onSelectionChanged.
// https://github.com/flutter/flutter/issues/76349.
try {
widget.onSelectionChanged?.call(selection, cause);
} catch (exception, stack) {
Expand Down

0 comments on commit 8868819

Please sign in to comment.