From 9512a53f706536f41532f9501ab7f158ffa85cd8 Mon Sep 17 00:00:00 2001 From: X Code Date: Mon, 14 Feb 2022 07:34:14 -0800 Subject: [PATCH] Remove shortcut --- lib/src/widgets/shortcut.dart | 99 ----------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 lib/src/widgets/shortcut.dart diff --git a/lib/src/widgets/shortcut.dart b/lib/src/widgets/shortcut.dart deleted file mode 100644 index 5cf28b8a..00000000 --- a/lib/src/widgets/shortcut.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; - -import '../models/documents/attribute.dart'; -import 'raw_editor.dart'; - -class QuillShortcuts extends Shortcuts { - QuillShortcuts({required Widget child, Key? key}) - : super( - key: key, - shortcuts: _shortcuts, - child: child, - ); - - static Map get _shortcuts { - switch (defaultTargetPlatform) { - case TargetPlatform.android: - return _defaultShortcuts; - case TargetPlatform.fuchsia: - return _defaultShortcuts; - case TargetPlatform.iOS: - return _macShortcuts; - case TargetPlatform.linux: - return _defaultShortcuts; - case TargetPlatform.macOS: - return _macShortcuts; - case TargetPlatform.windows: - return _defaultShortcuts; - } - } - - static const Map _defaultShortcuts = - { - SingleActivator(LogicalKeyboardKey.keyB, control: true): - ToggleBoldStyleIntent(), - SingleActivator(LogicalKeyboardKey.keyI, control: true): - ToggleItalicStyleIntent(), - SingleActivator(LogicalKeyboardKey.keyU, control: true): - ToggleUnderlineStyleIntent(), - }; - - static final Map _macShortcuts = - { - const SingleActivator(LogicalKeyboardKey.keyB, meta: true): - const ToggleBoldStyleIntent(), - const SingleActivator(LogicalKeyboardKey.keyI, meta: true): - const ToggleItalicStyleIntent(), - const SingleActivator(LogicalKeyboardKey.keyU, meta: true): - const ToggleUnderlineStyleIntent(), - }; -} - -class ToggleBoldStyleIntent extends Intent { - const ToggleBoldStyleIntent(); -} - -class ToggleItalicStyleIntent extends Intent { - const ToggleItalicStyleIntent(); -} - -class ToggleUnderlineStyleIntent extends Intent { - const ToggleUnderlineStyleIntent(); -} - -class QuillActions extends Actions { - QuillActions({ - required Widget child, - Key? key, - }) : super( - key: key, - actions: _shortcutsActions, - child: child, - ); - - static final Map> _shortcutsActions = - >{ - ToggleBoldStyleIntent: _ToggleInlineStyleAction(Attribute.bold), - ToggleItalicStyleIntent: _ToggleInlineStyleAction(Attribute.italic), - ToggleUnderlineStyleIntent: _ToggleInlineStyleAction(Attribute.underline), - }; -} - -class _ToggleInlineStyleAction extends ContextAction { - _ToggleInlineStyleAction(this.attribute); - - final Attribute attribute; - - @override - Object? invoke(Intent intent, [BuildContext? context]) { - final editorState = context!.findAncestorStateOfType()!; - final style = editorState.controller.getSelectionStyle(); - final actualAttr = style.containsKey(attribute.key) - ? Attribute.clone(attribute, null) - : attribute; - editorState.controller.formatSelection(actualAttr); - return null; - } -}