mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: trigger shortcut event by character (#2101)
This commit is contained in:
parent
3039f0427f
commit
1536cdd15a
@ -129,7 +129,7 @@ class _AppFlowyKeyboardState extends State<AppFlowyKeyboard>
|
||||
|
||||
// TODO: use cache to optimize the searching time.
|
||||
for (final shortcutEvent in widget.shortcutEvents) {
|
||||
if (shortcutEvent.keybindings.containsKeyEvent(event)) {
|
||||
if (shortcutEvent.canRespondToRawKeyEvent(event)) {
|
||||
final result = shortcutEvent.handler(widget.editorState, event);
|
||||
if (result == KeyEventResult.handled) {
|
||||
return KeyEventResult.handled;
|
||||
@ -157,3 +157,10 @@ class _AppFlowyKeyboardState extends State<AppFlowyKeyboard>
|
||||
return onKey(event);
|
||||
}
|
||||
}
|
||||
|
||||
extension on ShortcutEvent {
|
||||
bool canRespondToRawKeyEvent(RawKeyEvent event) {
|
||||
return ((character?.isNotEmpty ?? false) && character == event.character) ||
|
||||
keybindings.containsKeyEvent(event);
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ List<ShortcutEvent> builtInShortcutEvents = [
|
||||
),
|
||||
ShortcutEvent(
|
||||
key: 'selection menu',
|
||||
command: 'slash,shift+slash',
|
||||
character: '/',
|
||||
handler: slashShortcutHandler,
|
||||
),
|
||||
ShortcutEvent(
|
||||
@ -304,7 +304,7 @@ List<ShortcutEvent> builtInShortcutEvents = [
|
||||
),
|
||||
ShortcutEvent(
|
||||
key: 'Underscore to italic',
|
||||
command: 'shift+underscore',
|
||||
character: '_',
|
||||
handler: underscoreToItalicHandler,
|
||||
),
|
||||
ShortcutEvent(
|
||||
|
@ -8,12 +8,29 @@ import 'package:flutter/foundation.dart';
|
||||
class ShortcutEvent {
|
||||
ShortcutEvent({
|
||||
required this.key,
|
||||
required this.command,
|
||||
this.character,
|
||||
this.command,
|
||||
required this.handler,
|
||||
String? windowsCommand,
|
||||
String? macOSCommand,
|
||||
String? linuxCommand,
|
||||
}) {
|
||||
// character and command cannot be null at the same time
|
||||
assert(
|
||||
!(character == null &&
|
||||
command == null &&
|
||||
windowsCommand == null &&
|
||||
macOSCommand == null &&
|
||||
linuxCommand == null),
|
||||
'character and command cannot be null at the same time');
|
||||
assert(
|
||||
!(character != null &&
|
||||
(command != null &&
|
||||
windowsCommand != null &&
|
||||
macOSCommand != null &&
|
||||
linuxCommand != null)),
|
||||
'character and command cannot be set at the same time');
|
||||
|
||||
updateCommand(
|
||||
command: command,
|
||||
windowsCommand: windowsCommand,
|
||||
@ -43,7 +60,9 @@ class ShortcutEvent {
|
||||
///
|
||||
/// Like, 'ctrl+c,cmd+c'
|
||||
///
|
||||
String command;
|
||||
String? command;
|
||||
|
||||
String? character;
|
||||
|
||||
final ShortcutEventHandler handler;
|
||||
|
||||
@ -80,9 +99,9 @@ class ShortcutEvent {
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
if (matched && this.command != null) {
|
||||
_keybindings = this
|
||||
.command
|
||||
.command!
|
||||
.split(',')
|
||||
.map((e) => Keybinding.parse(e))
|
||||
.toList(growable: false);
|
||||
|
@ -121,7 +121,7 @@ packages:
|
||||
name: build_daemon
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
version: "3.1.1"
|
||||
build_resolvers:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -156,7 +156,7 @@ packages:
|
||||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.4.3"
|
||||
version: "8.4.4"
|
||||
calendar_view:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -500,7 +500,7 @@ packages:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.7"
|
||||
version: "2.0.9"
|
||||
flutter_svg:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -524,7 +524,7 @@ packages:
|
||||
name: fluttertoast
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.1.2"
|
||||
version: "8.2.1"
|
||||
freezed:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@ -599,7 +599,7 @@ packages:
|
||||
name: html
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.15.1"
|
||||
version: "0.15.2"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -709,7 +709,7 @@ packages:
|
||||
name: logger
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.3.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -779,7 +779,7 @@ packages:
|
||||
name: node_preamble
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
version: "2.0.2"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -856,35 +856,35 @@ packages:
|
||||
name: path_provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.12"
|
||||
version: "2.0.14"
|
||||
path_provider_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.22"
|
||||
version: "2.0.24"
|
||||
path_provider_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_foundation
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.2.0"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_linux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
version: "2.1.10"
|
||||
path_provider_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.5"
|
||||
version: "2.0.6"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -898,7 +898,7 @@ packages:
|
||||
name: percent_indicator
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.2.2"
|
||||
version: "4.2.3"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -919,7 +919,7 @@ packages:
|
||||
name: plugin_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
version: "2.1.4"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1024,7 +1024,7 @@ packages:
|
||||
name: rich_clipboard_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "1.0.2"
|
||||
screen_retriever:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1038,49 +1038,49 @@ packages:
|
||||
name: shared_preferences
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.17"
|
||||
version: "2.0.20"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.15"
|
||||
version: "2.0.17"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
version: "2.1.5"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
version: "2.1.5"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
version: "2.0.6"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
version: "2.1.5"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1122,7 +1122,7 @@ packages:
|
||||
name: sized_context
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0+1"
|
||||
version: "1.0.0+4"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -1155,7 +1155,7 @@ packages:
|
||||
name: source_maps
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.10.11"
|
||||
version: "0.10.12"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1295,56 +1295,56 @@ packages:
|
||||
name: url_launcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.9"
|
||||
version: "6.1.10"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.0.23"
|
||||
version: "6.0.26"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_ios
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.0"
|
||||
version: "6.1.3"
|
||||
url_launcher_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_linux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
version: "3.0.4"
|
||||
url_launcher_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
version: "3.0.4"
|
||||
url_launcher_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.14"
|
||||
version: "2.0.16"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.3"
|
||||
version: "3.0.5"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1407,7 +1407,7 @@ packages:
|
||||
name: window_manager
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
version: "0.3.1"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
Loading…
Reference in New Issue
Block a user