Skip to content

Commit e68cd90

Browse files
[SuperEditor][iOS] Fix caret blinking while dragging (Resolves #2104) (#2185)
1 parent 8a609dc commit e68cd90

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

super_editor/lib/src/infrastructure/platforms/ios/ios_document_controls.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class IosControlsDocumentLayerState extends DocumentLayoutLayerState<IosHandlesD
643643

644644
void _startOrStopBlinking() {
645645
// TODO: allow a configurable policy as to whether to show the caret at all when the selection is expanded: https://github.com/superlistapp/super_editor/issues/234
646-
final wantsToBlink = widget.selection.value != null;
646+
final wantsToBlink = widget.selection.value != null && widget.shouldCaretBlink.value;
647647
if (wantsToBlink && _caretBlinkController.isBlinking) {
648648
return;
649649
}

super_editor/test/super_editor/mobile/super_editor_ios_overlay_controls_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,46 @@ void main() {
6060
await tester.pump(const Duration(milliseconds: 100));
6161
});
6262

63+
testWidgetsOnIos("does not blink caret while dragging it", (tester) async {
64+
BlinkController.indeterminateAnimationsEnabled = true;
65+
addTearDown(() => BlinkController.indeterminateAnimationsEnabled = false);
66+
67+
await _pumpSingleParagraphApp(tester);
68+
69+
// Place the caret.
70+
await tester.tapInParagraph("1", 200);
71+
72+
// Press and drag the caret somewhere else in the paragraph.
73+
final gesture = await tester.tapDownInParagraph("1", 200);
74+
for (int i = 0; i < 5; i += 1) {
75+
await gesture.moveBy(const Offset(24, 0));
76+
await tester.pump();
77+
}
78+
79+
// Duration for the caret to switch between visible and invisible.
80+
final flashPeriod = SuperEditorInspector.caretFlashPeriod();
81+
82+
// Ensure caret is visible.
83+
expect(SuperEditorInspector.isCaretVisible(), isTrue);
84+
85+
// Trigger a frame with an ellapsed time equal to the flashPeriod,
86+
// so if the caret is blinking it will change from visible to invisible.
87+
await tester.pump(flashPeriod);
88+
89+
// Ensure caret is still visible after the flash period, which means it isn't blinking.
90+
expect(SuperEditorInspector.isCaretVisible(), isTrue);
91+
92+
// Trigger another frame.
93+
await tester.pump(flashPeriod);
94+
95+
// Ensure caret is still visible.
96+
expect(SuperEditorInspector.isCaretVisible(), isTrue);
97+
98+
// Resolve the gesture so that we don't have pending gesture timers.
99+
await gesture.up();
100+
await tester.pump(const Duration(milliseconds: 100));
101+
});
102+
63103
testWidgetsOnIos("shows toolbar when selection is expanded", (tester) async {
64104
await _pumpSingleParagraphApp(tester);
65105

0 commit comments

Comments
 (0)