diff --git a/packages/fleather/lib/src/widgets/editor.dart b/packages/fleather/lib/src/widgets/editor.dart index a9b82990..3b0dacca 100644 --- a/packages/fleather/lib/src/widgets/editor.dart +++ b/packages/fleather/lib/src/widgets/editor.dart @@ -1627,7 +1627,8 @@ class RawEditorState extends EditorState bool _showCaretOnScreenScheduled = false; void _showCaretOnScreen([bool withAnimation = true]) { - if (!widget.showCursor || + if (!_hasFocus || + !widget.showCursor || !widget.enableInteractiveSelection || _showCaretOnScreenScheduled) { return; diff --git a/packages/fleather/test/widgets/editor_test.dart b/packages/fleather/test/widgets/editor_test.dart index 70f23e45..05705ab4 100644 --- a/packages/fleather/test/widgets/editor_test.dart +++ b/packages/fleather/test/widgets/editor_test.dart @@ -1632,6 +1632,44 @@ void main() { await tester.pump(throttleDuration); }); + testWidgets('does not reveal cursor or editor when not focused', + (tester) async { + final scrollController = ScrollController(); + final controller = FleatherController(); + final widget = MaterialApp( + home: SingleChildScrollView( + controller: scrollController, + child: SizedBox( + width: double.maxFinite, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + for (var i = 0; i < 20; i++) ...[ + FleatherField( + key: Key('Field.Key.$i'), + focusNode: FocusNode(), + scrollable: false, + autofocus: true, + showCursor: true, + autocorrect: false, + enableSuggestions: false, + controller: i == 15 ? controller : FleatherController(), + ) + ] + ], + ), + ), + ), + ); + await tester.pumpWidget(widget); + final initialScrollPosition = scrollController.position.pixels; + final newInput = 'Line1\nLine2'; + controller.replaceText(0, 0, newInput, + selection: TextSelection.collapsed(offset: newInput.length)); + await tester.pumpAndSettle(throttleDuration); + expect(scrollController.position.pixels, initialScrollPosition); + }); + testWidgets( 'shows cursor on screen when not scrollable with scroll parent', (tester) async {