feat: customize command shortcuts (#2848)

This commit is contained in:
Mayur Mahajan
2023-07-20 13:41:00 +05:30
committed by GitHub
parent 5ab64f8835
commit b1378b4545
15 changed files with 1253 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import 'package:appflowy/plugins/document/application/doc_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/workspace/application/settings/shortcuts/settings_shortcuts_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/inline_page/inline_page_reference.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:collection/collection.dart';
@ -31,6 +32,15 @@ class AppFlowyEditorPage extends StatefulWidget {
State<AppFlowyEditorPage> createState() => _AppFlowyEditorPageState();
}
final List<CommandShortcutEvent> commandShortcutEvents = [
...codeBlockCommands,
...standardCommandShortcutEvents,
];
final List<CommandShortcutEvent> defaultCommandShortcutEvents = [
...commandShortcutEvents.map((e) => e.copyWith()).toList(),
];
class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
late final ScrollController effectiveScrollController;
@ -109,10 +119,10 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
void initState() {
super.initState();
_initializeShortcuts();
indentableBlockTypes.add(ToggleListBlockKeys.type);
convertibleBlockTypes.add(ToggleListBlockKeys.type);
slashMenuItems = _customSlashMenuItems();
effectiveScrollController = widget.scrollController ?? ScrollController();
}
@ -377,4 +387,16 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
}
return const (false, null);
}
Future<void> _initializeShortcuts() async {
//TODO(Xazin): Refactor lazy initialization
defaultCommandShortcutEvents;
final settingsShortcutService = SettingsShortcutService();
final customizeShortcuts =
await settingsShortcutService.getCustomizeShortcuts();
await settingsShortcutService.updateCommandShortcuts(
standardCommandShortcutEvents,
customizeShortcuts,
);
}
}