This is an automated email from the ASF dual-hosted git repository. damccorm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push: new cd9e00577e4 Run Playground code on Ctrl+Enter on numpad (#26516) (#26517) cd9e00577e4 is described below commit cd9e00577e45cf2d0bb7b98e5a28d30b0019bd2c Author: alexeyinkin <alexey.in...@akvelon.com> AuthorDate: Thu May 4 17:15:14 2023 +0400 Run Playground code on Ctrl+Enter on numpad (#26516) (#26517) * Run Playground code on Ctrl+Enter on numpad (#26516) * Upgrade flutter_code_editor (#26516) --- .../frontend/lib/shortcuts/shortcuts_manager.dart | 39 +++++++++++----------- learning/tour-of-beam/frontend/pubspec.lock | 4 +-- .../standalone_run_shortcuts_test.dart | 35 +++++++++---------- .../shortcuts/components/shortcuts_manager.dart | 33 +++++++++--------- .../lib/src/models/run_shortcut.dart | 17 ++++++++-- .../lib/src/widgets/run_button.dart | 2 +- .../frontend/playground_components/pubspec.yaml | 2 +- .../playground_components_dev/pubspec.yaml | 2 +- playground/frontend/pubspec.lock | 4 +-- playground/frontend/pubspec.yaml | 2 +- 10 files changed, 78 insertions(+), 62 deletions(-) diff --git a/learning/tour-of-beam/frontend/lib/shortcuts/shortcuts_manager.dart b/learning/tour-of-beam/frontend/lib/shortcuts/shortcuts_manager.dart index 0e992e7d4c4..229c9a18abc 100644 --- a/learning/tour-of-beam/frontend/lib/shortcuts/shortcuts_manager.dart +++ b/learning/tour-of-beam/frontend/lib/shortcuts/shortcuts_manager.dart @@ -35,27 +35,28 @@ class TobShortcutsManager extends StatelessWidget { return ShortcutsManager( shortcuts: [ ...tourNotifier.playgroundController.shortcuts, - BeamRunShortcut( - onInvoke: () { - final codeRunner = tourNotifier.playgroundController.codeRunner; - - if (codeRunner.canRun) { - codeRunner.runCode( - analyticsData: tourNotifier.tobEventContext.toJson(), - ); - - PlaygroundComponents.analyticsService.sendUnawaited( - RunStartedAnalyticsEvent( - snippetContext: codeRunner.eventSnippetContext!, - trigger: EventTrigger.shortcut, - additionalParams: codeRunner.analyticsData, - ), - ); - } - }, - ), + BeamMainRunShortcut(onInvoke: _onRun), + BeamNumpadRunShortcut(onInvoke: _onRun), ], child: child, ); } + + void _onRun() { + final codeRunner = tourNotifier.playgroundController.codeRunner; + + if (codeRunner.canRun) { + codeRunner.runCode( + analyticsData: tourNotifier.tobEventContext.toJson(), + ); + + PlaygroundComponents.analyticsService.sendUnawaited( + RunStartedAnalyticsEvent( + snippetContext: codeRunner.eventSnippetContext!, + trigger: EventTrigger.shortcut, + additionalParams: codeRunner.analyticsData, + ), + ); + } + } } diff --git a/learning/tour-of-beam/frontend/pubspec.lock b/learning/tour-of-beam/frontend/pubspec.lock index 7f071d272f0..bf9dc3abfd2 100644 --- a/learning/tour-of-beam/frontend/pubspec.lock +++ b/learning/tour-of-beam/frontend/pubspec.lock @@ -450,10 +450,10 @@ packages: dependency: transitive description: name: flutter_code_editor - sha256: "88b5d735e838658281dcd2b4b83437d8cdec9152fd174be147233e2f93fb01a9" + sha256: "53268d72dbe8daaf2a02f13863efd129cc37f599c1dcf85da33a4b34796ca8bd" url: "https://pub.dev" source: hosted - version: "0.2.20" + version: "0.2.21" flutter_driver: dependency: transitive description: flutter diff --git a/playground/frontend/integration_test/standalone_run_shortcuts_test.dart b/playground/frontend/integration_test/standalone_run_shortcuts_test.dart index 3264a963d6f..583015e65bf 100644 --- a/playground/frontend/integration_test/standalone_run_shortcuts_test.dart +++ b/playground/frontend/integration_test/standalone_run_shortcuts_test.dart @@ -35,8 +35,7 @@ void main() { final controller = wt.findPlaygroundController(); await _checkResetShortcut(wt, controller); - await _checkRunShortcut(wt, controller); - await _checkClearOutputShortcut(wt, controller); + await _checkRunAndClearShortcuts(wt, controller); }, ); } @@ -56,26 +55,28 @@ Future<void> _checkResetShortcut( expect(startSource, controller.source); } -Future<void> _checkRunShortcut( +Future<void> _checkRunAndClearShortcuts( WidgetTester wt, PlaygroundController controller, ) async { - final output = controller.codeRunner.resultLogOutput; - await wt.runShortcut(BeamRunShortcut(onInvoke: () {})); - await wt.pumpAndSettle(); + final oldOutput = controller.codeRunner.resultLogOutput; + final runShortcuts = [ + BeamMainRunShortcut(onInvoke: () {}), + BeamNumpadRunShortcut(onInvoke: () {}), + ]; - expect(output, isNot(controller.codeRunner.resultLogOutput)); -} + for (final shortcut in runShortcuts) { + await wt.runShortcut(shortcut); + await wt.pumpAndSettle(); -Future<void> _checkClearOutputShortcut( - WidgetTester wt, - PlaygroundController controller, -) async { - expect(controller.codeRunner.resultLogOutput, isNotEmpty); - expect(controller.codeRunner.resultLogOutput, isNotNull); + expect(controller.codeRunner.resultLogOutput, isNot(oldOutput)); - await wt.runShortcut(kClearOutputShortcut); - await wt.pumpAndSettle(); + expect(controller.codeRunner.resultLogOutput, isNotEmpty); + expect(controller.codeRunner.resultLogOutput, isNotNull); + + await wt.runShortcut(kClearOutputShortcut); + await wt.pumpAndSettle(); - expect(controller.codeRunner.resultLogOutput, isEmpty); + expect(controller.codeRunner.resultLogOutput, isEmpty); + } } diff --git a/playground/frontend/lib/modules/shortcuts/components/shortcuts_manager.dart b/playground/frontend/lib/modules/shortcuts/components/shortcuts_manager.dart index af6e4c2a3e9..3fb0bf16091 100644 --- a/playground/frontend/lib/modules/shortcuts/components/shortcuts_manager.dart +++ b/playground/frontend/lib/modules/shortcuts/components/shortcuts_manager.dart @@ -35,25 +35,26 @@ class PlaygroundShortcutsManager extends StatelessWidget { return ShortcutsManager( shortcuts: [ ...playgroundController.shortcuts, - BeamRunShortcut( - onInvoke: () { - final codeRunner = playgroundController.codeRunner; - - if (codeRunner.canRun) { - codeRunner.runCode(); - - PlaygroundComponents.analyticsService.sendUnawaited( - RunStartedAnalyticsEvent( - snippetContext: codeRunner.eventSnippetContext!, - trigger: EventTrigger.shortcut, - ), - ); - } - }, - ), + BeamMainRunShortcut(onInvoke: _onRun), + BeamNumpadRunShortcut(onInvoke: _onRun), ...globalShortcuts, ], child: child, ); } + + void _onRun() { + final codeRunner = playgroundController.codeRunner; + + if (codeRunner.canRun) { + codeRunner.runCode(); + + PlaygroundComponents.analyticsService.sendUnawaited( + RunStartedAnalyticsEvent( + snippetContext: codeRunner.eventSnippetContext!, + trigger: EventTrigger.shortcut, + ), + ); + } + } } diff --git a/playground/frontend/playground_components/lib/src/models/run_shortcut.dart b/playground/frontend/playground_components/lib/src/models/run_shortcut.dart index c5f067c6249..be27545129d 100644 --- a/playground/frontend/playground_components/lib/src/models/run_shortcut.dart +++ b/playground/frontend/playground_components/lib/src/models/run_shortcut.dart @@ -23,15 +23,16 @@ import '../util/logical_keyboard_key.dart'; import 'intents.dart'; import 'shortcut.dart'; -class BeamRunShortcut extends BeamShortcut { +abstract class BeamRunShortcut extends BeamShortcut { final VoidCallback onInvoke; BeamRunShortcut({ required this.onInvoke, + required LogicalKeyboardKey enterKey, }) : super( keys: [ LogicalKeyboardKeyExtension.metaOrControl, - LogicalKeyboardKey.enter, + enterKey, ], actionIntent: const RunIntent(), createAction: (BuildContext context) => CallbackAction( @@ -42,3 +43,15 @@ class BeamRunShortcut extends BeamShortcut { ), ); } + +class BeamMainRunShortcut extends BeamRunShortcut { + BeamMainRunShortcut({ + required super.onInvoke, + }) : super(enterKey: LogicalKeyboardKey.enter); +} + +class BeamNumpadRunShortcut extends BeamRunShortcut { + BeamNumpadRunShortcut({ + required super.onInvoke, + }) : super(enterKey: LogicalKeyboardKey.numpadEnter); +} diff --git a/playground/frontend/playground_components/lib/src/widgets/run_button.dart b/playground/frontend/playground_components/lib/src/widgets/run_button.dart index 9dc2caad561..a3654aa62c7 100644 --- a/playground/frontend/playground_components/lib/src/widgets/run_button.dart +++ b/playground/frontend/playground_components/lib/src/widgets/run_button.dart @@ -56,7 +56,7 @@ class RunButton extends StatelessWidget { width: _width, height: BeamSizes.buttonHeight, child: ShortcutTooltip( - shortcut: BeamRunShortcut( + shortcut: BeamMainRunShortcut( onInvoke: () {}, // Only the tooltip is used. ), child: ElevatedButton.icon( diff --git a/playground/frontend/playground_components/pubspec.yaml b/playground/frontend/playground_components/pubspec.yaml index 4329ad9ef3e..6b1459555c8 100644 --- a/playground/frontend/playground_components/pubspec.yaml +++ b/playground/frontend/playground_components/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: enum_map: ^0.2.1 equatable: ^2.0.5 flutter: { sdk: flutter } - flutter_code_editor: ^0.2.20 + flutter_code_editor: ^0.2.21 # TODO(nausharipov): return flutter_markdown when it is fixed, https://github.com/apache/beam/issues/26498 # The exact version is used because this non-official package can be poorly maintained. diff --git a/playground/frontend/playground_components_dev/pubspec.yaml b/playground/frontend/playground_components_dev/pubspec.yaml index 1b1b81fcea2..9b16e971ead 100644 --- a/playground/frontend/playground_components_dev/pubspec.yaml +++ b/playground/frontend/playground_components_dev/pubspec.yaml @@ -27,7 +27,7 @@ environment: dependencies: app_state: ^0.9.3 flutter: { sdk: flutter } - flutter_code_editor: ^0.2.20 + flutter_code_editor: ^0.2.21 flutter_test: { sdk: flutter } get_it: ^7.2.0 highlight: ^0.7.0 diff --git a/playground/frontend/pubspec.lock b/playground/frontend/pubspec.lock index 22213b56777..0a9af87dfd7 100644 --- a/playground/frontend/pubspec.lock +++ b/playground/frontend/pubspec.lock @@ -394,10 +394,10 @@ packages: dependency: "direct dev" description: name: flutter_code_editor - sha256: "88b5d735e838658281dcd2b4b83437d8cdec9152fd174be147233e2f93fb01a9" + sha256: "53268d72dbe8daaf2a02f13863efd129cc37f599c1dcf85da33a4b34796ca8bd" url: "https://pub.dev" source: hosted - version: "0.2.20" + version: "0.2.21" flutter_driver: dependency: transitive description: flutter diff --git a/playground/frontend/pubspec.yaml b/playground/frontend/pubspec.yaml index ea08d33a3fa..fe997344a22 100644 --- a/playground/frontend/pubspec.yaml +++ b/playground/frontend/pubspec.yaml @@ -52,7 +52,7 @@ dependencies: dev_dependencies: build_runner: ^2.1.4 fake_async: ^1.3.0 - flutter_code_editor: ^0.2.20 + flutter_code_editor: ^0.2.21 flutter_lints: ^2.0.1 flutter_test: { sdk: flutter } integration_test: { sdk: flutter }