Unverified Commit 2dc8bb18 authored by Swain's avatar Swain Committed by GitHub

Make the cursor no longer blinking when move, as same as the effect of iOS platform. (#107221)

parent 2327bb7b
......@@ -2184,6 +2184,9 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_floatingCursorResetController!.stop();
_onFloatingCursorResetTick();
}
// Stop cursor blinking and making it visible.
_stopCursorBlink(resetCharTicks: false);
_cursorBlinkOpacityController.value = 1.0;
// We want to send in points that are centered around a (0,0) origin, so
// we cache the position.
_pointOffsetOrigin = point.offset;
......@@ -2204,6 +2207,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
renderEditable.setFloatingCursor(point.state, _lastBoundedOffset!, _lastTextPosition!);
break;
case FloatingCursorDragState.End:
// Resume cursor blinking.
_startCursorBlink();
// We skip animation if no update has happened.
if (_lastTextPosition != null && _lastBoundedOffset != null) {
_floatingCursorResetController!.value = 0.0;
......
......@@ -701,6 +701,73 @@ void main() {
expect(tester.takeException(), null);
});
testWidgets("Drag the floating cursor, it won't blink.", (WidgetTester tester) async {
const String text = 'hello world this is fun and cool and awesome!';
controller.text = text;
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(),
child: Directionality(
textDirection: TextDirection.ltr,
child: FocusScope(
node: focusScopeNode,
autofocus: true,
child: EditableText(
backgroundCursorColor: Colors.grey,
controller: controller,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
),
),
),
),
);
final EditableTextState editableText = tester.state(find.byType(EditableText));
// Check that the cursor visibility toggles after each blink interval.
// Or if it's not blinking at all, it stays on.
Future<void> checkCursorBlinking({ bool isBlinking = true }) async {
bool initialShowCursor = true;
if (isBlinking) {
initialShowCursor = editableText.cursorCurrentlyVisible;
}
await tester.pump(editableText.cursorBlinkInterval);
expect(editableText.cursorCurrentlyVisible, equals(isBlinking ? !initialShowCursor : initialShowCursor));
await tester.pump(editableText.cursorBlinkInterval);
expect(editableText.cursorCurrentlyVisible, equals(initialShowCursor));
await tester.pump(editableText.cursorBlinkInterval ~/ 10);
expect(editableText.cursorCurrentlyVisible, equals(initialShowCursor));
await tester.pump(editableText.cursorBlinkInterval);
expect(editableText.cursorCurrentlyVisible, equals(isBlinking ? !initialShowCursor : initialShowCursor));
await tester.pump(editableText.cursorBlinkInterval);
expect(editableText.cursorCurrentlyVisible, equals(initialShowCursor));
}
final Offset textfieldStart = tester.getTopLeft(find.byType(EditableText));
await tester.tapAt(textfieldStart + const Offset(50.0, 9.0));
await tester.pumpAndSettle();
// Before dragging, the cursor should blink.
await checkCursorBlinking();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
editableTextState.updateFloatingCursor(RawFloatingCursorPoint(state: FloatingCursorDragState.Start));
// When drag cursor, the cursor shouldn't blink.
await checkCursorBlinking(isBlinking: false);
editableTextState.updateFloatingCursor(RawFloatingCursorPoint(state: FloatingCursorDragState.End));
await tester.pumpAndSettle();
// After dragging, the cursor should blink.
await checkCursorBlinking();
});
// Regression test for https://github.com/flutter/flutter/pull/30475.
testWidgets('Trying to select with the floating cursor does not crash', (WidgetTester tester) async {
const String text = 'hello world this is fun and cool and awesome!';
......
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