Unverified Commit 478d1dae authored by Lucas.Xu's avatar Lucas.Xu Committed by GitHub

remove the unused check in selectable_text (#117716)

parent 6c225dda
......@@ -558,8 +558,6 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
});
}
TextSelection? _lastSeenTextSelection;
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
if (willShowSelectionHandles != _showSelectionHandles) {
......@@ -567,12 +565,8 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
_showSelectionHandles = willShowSelectionHandles;
});
}
// 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;
widget.onSelectionChanged?.call(selection, cause);
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
......
......@@ -5367,4 +5367,43 @@ void main() {
final EditableText editableText = tester.widget(find.byType(EditableText));
expect(editableText.style.fontSize, textStyle.fontSize);
});
testWidgets('SelectableText text span style is merged with default text style', (WidgetTester tester) async {
TextSelection? selection;
int count = 0;
await tester.pumpWidget(
MaterialApp(
home: SelectableText(
'I love Flutter!',
onSelectionChanged: (TextSelection s, _) {
selection = s;
count++;
},
),
),
);
expect(selection, null);
expect(count, 0);
// Tap to put the cursor before the "F".
const int index = 7;
await tester.tapAt(textOffsetToPosition(tester, index));
await tester.pump(const Duration(milliseconds: 500));
expect(
selection,
const TextSelection.collapsed(offset: index),
);
expect(count, 1); // The `onSelectionChanged` will be triggered one time.
// Tap on the same location again.
await tester.tapAt(textOffsetToPosition(tester, index));
await tester.pump(const Duration(milliseconds: 50));
expect(
selection,
const TextSelection.collapsed(offset: index),
);
expect(count, 1); // The `onSelectionChanged` will not be triggered.
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment