Line data Source code
1 : // Copyright 2014 The Flutter Authors. 2 : // Copyright 2021 Suragch. 3 : // All rights reserved. 4 : // Use of this source code is governed by a BSD-style license that can be 5 : // found in the LICENSE file. 6 : 7 : // https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/text_editing_action.dart 8 : 9 : import 'package:flutter/widgets.dart' show Intent, ContextAction, StatefulElement, protected, primaryFocus; 10 : 11 : import 'mongol_render_editable.dart'; 12 : 13 : // import 'actions.dart'; 14 : // import 'editable_text.dart'; 15 : // import 'focus_manager.dart'; 16 : // import 'framework.dart'; 17 : 18 : /// The recipient of a [MongolTextEditingAction]. 19 : /// 20 : /// MongolTextEditingActions will only be enabled when an implementer of this 21 : /// class is focused. 22 : /// 23 : /// See also: 24 : /// 25 : /// * [MongolEditableTextState], which implements this and is the most typical 26 : /// target of a MongolTextEditingAction. 27 : abstract class MongolTextEditingActionTarget { 28 : /// The renderer that handles [MongolTextEditingAction]s. 29 : /// 30 : /// See also: 31 : /// 32 : /// * [MongolEditableTextState.renderEditable], which overrides this. 33 : MongolRenderEditable get renderEditable; 34 : } 35 : 36 : /// An [Action] related to editing text. 37 : /// 38 : /// Enables itself only when a [MongolTextEditingActionTarget], e.g. 39 : /// [MongolEditableText], is currently focused. The result of this is that when a 40 : /// MongolTextEditingActionTarget is not focused, it will fall through to any 41 : /// non-MongolTextEditingAction that handles the same shortcut. For example, 42 : /// overriding the tab key in [Shortcuts] with a MongolTextEditingAction will only 43 : /// invoke your MongolTextEditingAction when a MongolTextEditingActionTarget is focused, 44 : /// otherwise the default tab behavior will apply. 45 : /// 46 : /// The currently focused MongolTextEditingActionTarget is available in the [invoke] 47 : /// method via [textEditingActionTarget]. 48 : /// 49 : /// See also: 50 : /// 51 : /// * [CallbackAction], which is a similar Action type but unrelated to text 52 : /// editing. 53 : abstract class MongolTextEditingAction<T extends Intent> extends ContextAction<T> { 54 : /// Returns the currently focused [MongolTextEditingAction], or null if none is 55 : /// focused. 56 0 : @protected 57 : MongolTextEditingActionTarget? get textEditingActionTarget { 58 : // If a MongolTextEditingActionTarget is not focused, then ignore this action. 59 0 : if (primaryFocus?.context == null 60 0 : || primaryFocus!.context! is! StatefulElement 61 0 : || ((primaryFocus!.context! as StatefulElement).state is! MongolTextEditingActionTarget)) { 62 : return null; 63 : } 64 0 : return (primaryFocus!.context! as StatefulElement).state as MongolTextEditingActionTarget; 65 : } 66 : 67 0 : @override 68 : bool isEnabled(T intent) { 69 : // The Action is disabled if there is no focused MongolTextEditingActionTarget. 70 0 : return textEditingActionTarget != null; 71 : } 72 : }