`simplistic_editor` : Fix keyboard shortcuts on `macOS` (#1684)

* Define performSelector to receive intents from macOS TextInputPlugin and remove local Shortcuts widget to inherit DefaultTextEditingShortcuts

* dart format
pull/1687/head
Renzo Olivares 2 years ago committed by GitHub
parent 37af63583f
commit 881a439868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -111,7 +111,14 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
@override @override
void performSelector(String selectorName) { void performSelector(String selectorName) {
// Will not implement. final Intent? intent = intentForMacOSSelector(selectorName);
if (intent != null) {
final BuildContext? primaryContext = primaryFocus?.context;
if (primaryContext != null) {
Actions.invoke(primaryContext, intent);
}
}
} }
@override @override
@ -773,82 +780,61 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
} }
} }
static final Map<ShortcutActivator, Intent> _defaultWebShortcuts =
<ShortcutActivator, Intent>{
// Activation
const SingleActivator(LogicalKeyboardKey.space):
const DoNothingAndStopPropagationIntent(),
// Scrolling
const SingleActivator(LogicalKeyboardKey.arrowUp):
const DoNothingAndStopPropagationIntent(),
const SingleActivator(LogicalKeyboardKey.arrowDown):
const DoNothingAndStopPropagationIntent(),
const SingleActivator(LogicalKeyboardKey.arrowLeft):
const DoNothingAndStopPropagationIntent(),
const SingleActivator(LogicalKeyboardKey.arrowRight):
const DoNothingAndStopPropagationIntent(),
};
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Shortcuts( return Actions(
shortcuts: kIsWeb ? _defaultWebShortcuts : <ShortcutActivator, Intent>{}, actions: _actions,
child: Actions( child: Focus(
actions: _actions, focusNode: widget.focusNode,
child: Focus( child: Scrollable(
focusNode: widget.focusNode, viewportBuilder: (context, position) {
child: Scrollable( return CompositedTransformTarget(
viewportBuilder: (context, position) { link: _toolbarLayerLink,
return CompositedTransformTarget( child: _Editable(
link: _toolbarLayerLink, key: _textKey,
child: _Editable( startHandleLayerLink: _startHandleLayerLink,
key: _textKey, endHandleLayerLink: _endHandleLayerLink,
startHandleLayerLink: _startHandleLayerLink, inlineSpan: _buildTextSpan(),
endHandleLayerLink: _endHandleLayerLink, value: _value, // We pass value.selection to RenderEditable.
inlineSpan: _buildTextSpan(), cursorColor: Colors.blue,
value: _value, // We pass value.selection to RenderEditable. backgroundCursorColor: Colors.grey[100],
cursorColor: Colors.blue, showCursor: ValueNotifier<bool>(_hasFocus),
backgroundCursorColor: Colors.grey[100], forceLine:
showCursor: ValueNotifier<bool>(_hasFocus), true, // Whether text field will take full line regardless of width.
forceLine: readOnly: false, // editable text-field.
true, // Whether text field will take full line regardless of width. hasFocus: _hasFocus,
readOnly: false, // editable text-field. maxLines: null, // multi-line text-field.
hasFocus: _hasFocus, minLines: null,
maxLines: null, // multi-line text-field. expands: false, // expands to height of parent.
minLines: null, strutStyle: null,
expands: false, // expands to height of parent. selectionColor: Colors.blue.withOpacity(0.40),
strutStyle: null, textScaleFactor: MediaQuery.textScaleFactorOf(context),
selectionColor: Colors.blue.withOpacity(0.40), textAlign: TextAlign.left,
textScaleFactor: MediaQuery.textScaleFactorOf(context), textDirection: _textDirection,
textAlign: TextAlign.left, locale: Localizations.maybeLocaleOf(context),
textDirection: _textDirection, textHeightBehavior: DefaultTextHeightBehavior.maybeOf(context),
locale: Localizations.maybeLocaleOf(context), textWidthBasis: TextWidthBasis.parent,
textHeightBehavior: obscuringCharacter: '',
DefaultTextHeightBehavior.maybeOf(context), obscureText:
textWidthBasis: TextWidthBasis.parent, false, // This is a non-private text field that does not require obfuscation.
obscuringCharacter: '', offset: position,
obscureText: onCaretChanged: null,
false, // This is a non-private text field that does not require obfuscation. rendererIgnoresPointer: true,
offset: position, cursorWidth: 2.0,
onCaretChanged: null, cursorHeight: null,
rendererIgnoresPointer: true, cursorRadius: const Radius.circular(2.0),
cursorWidth: 2.0, cursorOffset: Offset.zero,
cursorHeight: null, paintCursorAboveText: false,
cursorRadius: const Radius.circular(2.0), enableInteractiveSelection:
cursorOffset: Offset.zero, true, // make true to enable selection on mobile.
paintCursorAboveText: false, textSelectionDelegate: this,
enableInteractiveSelection: devicePixelRatio: MediaQuery.of(context).devicePixelRatio,
true, // make true to enable selection on mobile. promptRectRange: null,
textSelectionDelegate: this, promptRectColor: null,
devicePixelRatio: MediaQuery.of(context).devicePixelRatio, clipBehavior: Clip.hardEdge,
promptRectRange: null, ),
promptRectColor: null, );
clipBehavior: Clip.hardEdge, },
),
);
},
),
), ),
), ),
); );

Loading…
Cancel
Save