Skip to content

Commit ebd507e

Browse files
authored
Fix editor reveals cursor and widget when not focused (#569)
1 parent d5c1f09 commit ebd507e

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

packages/fleather/lib/src/widgets/editor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,8 @@ class RawEditorState extends EditorState
16271627
bool _showCaretOnScreenScheduled = false;
16281628

16291629
void _showCaretOnScreen([bool withAnimation = true]) {
1630-
if (!widget.showCursor ||
1630+
if (!_hasFocus ||
1631+
!widget.showCursor ||
16311632
!widget.enableInteractiveSelection ||
16321633
_showCaretOnScreenScheduled) {
16331634
return;

packages/fleather/test/widgets/editor_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,44 @@ void main() {
16321632
await tester.pump(throttleDuration);
16331633
});
16341634

1635+
testWidgets('does not reveal cursor or editor when not focused',
1636+
(tester) async {
1637+
final scrollController = ScrollController();
1638+
final controller = FleatherController();
1639+
final widget = MaterialApp(
1640+
home: SingleChildScrollView(
1641+
controller: scrollController,
1642+
child: SizedBox(
1643+
width: double.maxFinite,
1644+
child: Column(
1645+
crossAxisAlignment: CrossAxisAlignment.start,
1646+
children: [
1647+
for (var i = 0; i < 20; i++) ...[
1648+
FleatherField(
1649+
key: Key('Field.Key.$i'),
1650+
focusNode: FocusNode(),
1651+
scrollable: false,
1652+
autofocus: true,
1653+
showCursor: true,
1654+
autocorrect: false,
1655+
enableSuggestions: false,
1656+
controller: i == 15 ? controller : FleatherController(),
1657+
)
1658+
]
1659+
],
1660+
),
1661+
),
1662+
),
1663+
);
1664+
await tester.pumpWidget(widget);
1665+
final initialScrollPosition = scrollController.position.pixels;
1666+
final newInput = 'Line1\nLine2';
1667+
controller.replaceText(0, 0, newInput,
1668+
selection: TextSelection.collapsed(offset: newInput.length));
1669+
await tester.pumpAndSettle(throttleDuration);
1670+
expect(scrollController.position.pixels, initialScrollPosition);
1671+
});
1672+
16351673
testWidgets(
16361674
'shows cursor on screen when not scrollable with scroll parent',
16371675
(tester) async {

0 commit comments

Comments
 (0)