From 0df841ac9223db3bf0dc5807d0a13d31664d5b6b Mon Sep 17 00:00:00 2001 From: Darkhan Nausharipov Date: Tue, 6 Jun 2023 23:17:26 +0600 Subject: [PATCH 1/5] _suggestionsCloseNotifier --- lib/src/code_field/code_field.dart | 6 +++++- lib/src/util/public_notifier.dart | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/src/util/public_notifier.dart diff --git a/lib/src/code_field/code_field.dart b/lib/src/code_field/code_field.dart index 15146eaf..1f4dd7c3 100644 --- a/lib/src/code_field/code_field.dart +++ b/lib/src/code_field/code_field.dart @@ -9,6 +9,7 @@ import '../gutter/gutter.dart'; import '../line_numbers/gutter_style.dart'; import '../search/widget/search_widget.dart'; import '../sizes.dart'; +import '../util/public_notifier.dart'; import '../wip/autocomplete/popup.dart'; import 'actions/comment_uncomment.dart'; import 'actions/enter_key.dart'; @@ -186,7 +187,7 @@ class CodeField extends StatefulWidget { this.onChanged, @Deprecated('Use gutterStyle instead') this.lineNumbers, @Deprecated('Use gutterStyle instead') - this.lineNumberStyle = const GutterStyle(), + this.lineNumberStyle = const GutterStyle(), }) : assert( gutterStyle == null || lineNumbers == null, 'Can not provide gutterStyle and lineNumbers at the same time. ' @@ -207,6 +208,7 @@ class _CodeFieldState extends State { final _codeFieldKey = GlobalKey(); OverlayEntry? _suggestionsPopup; + final _suggestionsCloseNotifier = PublicNotifier(); OverlayEntry? _searchPopup; Offset _normalPopupOffset = Offset.zero; Offset _flippedPopupOffset = Offset.zero; @@ -264,6 +266,7 @@ class _CodeFieldState extends State { widget.controller.removeListener(_onTextChanged); widget.controller.removeListener(_updatePopupOffset); widget.controller.popupController.removeListener(_onPopupStateChanged); + _suggestionsCloseNotifier.notifyPublic(); widget.controller.searchController.removeListener( _onSearchControllerChange, ); @@ -549,6 +552,7 @@ class _CodeFieldState extends State { if (_suggestionsPopup == null) { _suggestionsPopup = _buildSuggestionOverlay(); + _suggestionsCloseNotifier.addListener(_suggestionsPopup!.remove); Overlay.of(context).insert(_suggestionsPopup!); } diff --git a/lib/src/util/public_notifier.dart b/lib/src/util/public_notifier.dart new file mode 100644 index 00000000..5a5a0973 --- /dev/null +++ b/lib/src/util/public_notifier.dart @@ -0,0 +1,9 @@ +import 'package:flutter/material.dart'; + +/// Exposes notifyListeners that was protected in the superclass. +/// +/// Use this object when you need to fire callbacks that for some +/// reason cannot listen to the object you write your code in. +class PublicNotifier extends ChangeNotifier { + void notifyPublic() => notifyListeners(); +} From a08ffaf519e51608298674af4d29fa7523646044 Mon Sep 17 00:00:00 2001 From: Darkhan Nausharipov Date: Wed, 7 Jun 2023 12:12:49 +0600 Subject: [PATCH 2/5] removed public notifier --- lib/src/code_field/code_field.dart | 5 +---- lib/src/util/public_notifier.dart | 9 --------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 lib/src/util/public_notifier.dart diff --git a/lib/src/code_field/code_field.dart b/lib/src/code_field/code_field.dart index 1f4dd7c3..51dfb0cc 100644 --- a/lib/src/code_field/code_field.dart +++ b/lib/src/code_field/code_field.dart @@ -9,7 +9,6 @@ import '../gutter/gutter.dart'; import '../line_numbers/gutter_style.dart'; import '../search/widget/search_widget.dart'; import '../sizes.dart'; -import '../util/public_notifier.dart'; import '../wip/autocomplete/popup.dart'; import 'actions/comment_uncomment.dart'; import 'actions/enter_key.dart'; @@ -208,7 +207,6 @@ class _CodeFieldState extends State { final _codeFieldKey = GlobalKey(); OverlayEntry? _suggestionsPopup; - final _suggestionsCloseNotifier = PublicNotifier(); OverlayEntry? _searchPopup; Offset _normalPopupOffset = Offset.zero; Offset _flippedPopupOffset = Offset.zero; @@ -266,7 +264,7 @@ class _CodeFieldState extends State { widget.controller.removeListener(_onTextChanged); widget.controller.removeListener(_updatePopupOffset); widget.controller.popupController.removeListener(_onPopupStateChanged); - _suggestionsCloseNotifier.notifyPublic(); + _suggestionsPopup?.remove(); widget.controller.searchController.removeListener( _onSearchControllerChange, ); @@ -552,7 +550,6 @@ class _CodeFieldState extends State { if (_suggestionsPopup == null) { _suggestionsPopup = _buildSuggestionOverlay(); - _suggestionsCloseNotifier.addListener(_suggestionsPopup!.remove); Overlay.of(context).insert(_suggestionsPopup!); } diff --git a/lib/src/util/public_notifier.dart b/lib/src/util/public_notifier.dart deleted file mode 100644 index 5a5a0973..00000000 --- a/lib/src/util/public_notifier.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter/material.dart'; - -/// Exposes notifyListeners that was protected in the superclass. -/// -/// Use this object when you need to fire callbacks that for some -/// reason cannot listen to the object you write your code in. -class PublicNotifier extends ChangeNotifier { - void notifyPublic() => notifyListeners(); -} From eab3efefe4c5d08866c83ad1856eb0775d952fd7 Mon Sep 17 00:00:00 2001 From: Alexey Inkin Date: Wed, 7 Jun 2023 11:58:10 +0400 Subject: [PATCH 3/5] Auto-format, update Flutter version in CI (#241) --- .github/workflows/dart.yaml | 2 +- lib/src/code_field/code_controller.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dart.yaml b/.github/workflows/dart.yaml index 5f127eea..c860f932 100644 --- a/.github/workflows/dart.yaml +++ b/.github/workflows/dart.yaml @@ -7,7 +7,7 @@ on: branches: [ '**' ] env: - flutter_version: 3.7.1 + flutter_version: 3.10.2 jobs: build: diff --git a/lib/src/code_field/code_controller.dart b/lib/src/code_field/code_controller.dart index 8d2d166a..5d1864c7 100644 --- a/lib/src/code_field/code_controller.dart +++ b/lib/src/code_field/code_controller.dart @@ -144,7 +144,7 @@ class CodeController extends TextEditingController { Set readOnlySectionNames = const {}, Set visibleSectionNames = const {}, @Deprecated('Use CodeTheme widget to provide theme to CodeField.') - Map? theme, + Map? theme, this.analysisResult = const AnalysisResult(issues: []), this.patternMap, this.readOnly = false, From 76cef89d6eb93732d191c53b56fa8c4770fb57c8 Mon Sep 17 00:00:00 2001 From: Alexey Inkin Date: Wed, 7 Jun 2023 12:09:36 +0400 Subject: [PATCH 4/5] Fix analyzer issues (#241) --- lib/src/gutter/gutter.dart | 3 +++ .../code_field/code_controller_shortcut_test.dart | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/gutter/gutter.dart b/lib/src/gutter/gutter.dart index c417a9f8..88c7424e 100644 --- a/lib/src/gutter/gutter.dart +++ b/lib/src/gutter/gutter.dart @@ -1,3 +1,6 @@ +// TODO(alexeyinkin): Remove when dropping support for Flutter < 3.10, https://github.com/akvelon/flutter-code-editor/issues/245 +// ignore_for_file: unnecessary_non_null_assertion + import 'package:flutter/material.dart'; import '../code_field/code_controller.dart'; diff --git a/test/src/code_field/code_controller_shortcut_test.dart b/test/src/code_field/code_controller_shortcut_test.dart index 3d63c241..01303fac 100644 --- a/test/src/code_field/code_controller_shortcut_test.dart +++ b/test/src/code_field/code_controller_shortcut_test.dart @@ -18,12 +18,16 @@ class MyClass { void main() { final calls = []; - void mockClipboardHandler() { + void mockClipboardHandler(WidgetTester wt) { calls.clear(); - SystemChannels.platform.setMockMethodCallHandler((MethodCall call) async { - calls.add(call); - }); + wt.binding.defaultBinaryMessenger.setMockMethodCallHandler( + SystemChannels.platform, + (MethodCall call) async { + calls.add(call); + return null; + }, + ); } group('CodeController. Shortcuts.', () { @@ -97,7 +101,7 @@ void main() { controller.value = const TextEditingValue(text: MethodSnippet.full); controller.foldAt(1); await wt.selectFromHome(18, offset: 16); - mockClipboardHandler(); + mockClipboardHandler(wt); await example.act(); From 90d2d54d77e25e0d9a8794a3100ccd877f1f828b Mon Sep 17 00:00:00 2001 From: Alexey Inkin Date: Wed, 7 Jun 2023 12:37:22 +0400 Subject: [PATCH 5/5] Fix tests (#241) --- test/src/code_field/code_controller_readonly_test.dart | 2 -- test/src/history/code_history_controller_test.dart | 2 -- 2 files changed, 4 deletions(-) diff --git a/test/src/code_field/code_controller_readonly_test.dart b/test/src/code_field/code_controller_readonly_test.dart index 7ffe1df7..e89586e2 100644 --- a/test/src/code_field/code_controller_readonly_test.dart +++ b/test/src/code_field/code_controller_readonly_test.dart @@ -121,7 +121,6 @@ void main() { // cursor / selection: TextSelection.collapsed( offset: 14, - affinity: TextAffinity.upstream, ), ), reason: 'Delete - no effect', @@ -460,7 +459,6 @@ void main() { // cursor / selection: TextSelection.collapsed( offset: 10, - affinity: TextAffinity.upstream, ), ), reason: 'Backspace Delete Type at last empty line - No effect', diff --git a/test/src/history/code_history_controller_test.dart b/test/src/history/code_history_controller_test.dart index f0609a39..f5faec4a 100644 --- a/test/src/history/code_history_controller_test.dart +++ b/test/src/history/code_history_controller_test.dart @@ -258,7 +258,6 @@ void main() { controller.selection, const TextSelection.collapsed( offset: MethodSnippet.visible.length, - affinity: TextAffinity.upstream, ), ); @@ -269,7 +268,6 @@ void main() { controller.selection, const TextSelection.collapsed( offset: MethodSnippet.visible.length, - affinity: TextAffinity.upstream, ), ); });