Unverified Commit 0aec2c3d authored by tgucio's avatar tgucio Committed by GitHub

Restart EditableText cursor timer when it moves (#70787)

parent 720f366f
......@@ -2089,6 +2089,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
));
}
}
// To keep the cursor from blinking while it moves, restart the timer here.
if (_cursorTimer != null) {
_stopCursorTimer(resetCharTicks: false);
_startCursorTimer();
}
}
bool _textChangedSinceLastCaretUpdate = false;
......
......@@ -323,6 +323,81 @@ void main() {
EditableText.debugDeterministicCursor = false;
});
testWidgets('Cursor animation restarts when it is moved using keys on desktop', (WidgetTester tester) async {
const String testText = 'Some text long enough to move the cursor around';
final TextEditingController controller = TextEditingController(text: testText);
final Widget widget = MaterialApp(
home: EditableText(
controller: controller,
focusNode: FocusNode(),
style: const TextStyle(fontSize: 20.0),
maxLines: 1,
cursorColor: Colors.blue,
backgroundCursorColor: Colors.grey,
cursorOpacityAnimates: false,
selectionControls: materialTextSelectionControls,
keyboardType: TextInputType.text,
textAlign: TextAlign.left,
),
);
await tester.pumpWidget(widget);
await tester.tap(find.byType(EditableText));
await tester.pump();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable;
await tester.pump();
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
// Android cursor goes from exactly on to exactly off on the 500ms dot.
await tester.pump(const Duration(milliseconds: 499));
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowLeft);
await tester.pump();
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowLeft);
await tester.pump();
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.pump(const Duration(milliseconds: 200));
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.pump(const Duration(milliseconds: 299));
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowRight);
await tester.pump();
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.pump(const Duration(milliseconds: 200));
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.pump(const Duration(milliseconds: 299));
expect(renderEditable.cursorColor!.alpha, 255);
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
await tester.pump(const Duration(milliseconds: 1));
expect(renderEditable.cursorColor!.alpha, 0);
expect(renderEditable, paintsExactlyCountTimes(#drawRect, 0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS }));
testWidgets('Cursor does not show when showCursor set to false', (WidgetTester tester) async {
const Widget widget = MaterialApp(
home: Material(
......
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