@@ -705,6 +705,17 @@ class _TextFieldState extends State<TextField> implements TextSelectionGestureDe
705705
706706 bool _isHovering = false ;
707707
708+ // Disables all directional focus actions inside of a text field, since up and
709+ // down shouldn't go to another field, even in a single line text field. We
710+ // remap the keys rather than the actions, since someone might want to invoke
711+ // a directional navigation action from another key binding.
712+ final Map <LogicalKeySet , Intent > _disabledNavigationKeys = < LogicalKeySet , Intent > {
713+ LogicalKeySet (LogicalKeyboardKey .arrowUp): const Intent (DoNothingAction .key),
714+ LogicalKeySet (LogicalKeyboardKey .arrowDown): const Intent (DoNothingAction .key),
715+ LogicalKeySet (LogicalKeyboardKey .arrowLeft): const Intent (DoNothingAction .key),
716+ LogicalKeySet (LogicalKeyboardKey .arrowRight): const Intent (DoNothingAction .key),
717+ };
718+
708719 bool get needsCounter => widget.maxLength != null
709720 && widget.decoration != null
710721 && widget.decoration.counterText == null ;
@@ -936,49 +947,52 @@ class _TextFieldState extends State<TextField> implements TextSelectionGestureDe
936947 }
937948
938949 Widget child = RepaintBoundary (
939- child: EditableText (
940- key: editableTextKey,
941- readOnly: widget.readOnly,
942- toolbarOptions: widget.toolbarOptions,
943- showCursor: widget.showCursor,
944- showSelectionHandles: _showSelectionHandles,
945- controller: controller,
946- focusNode: focusNode,
947- keyboardType: widget.keyboardType,
948- textInputAction: widget.textInputAction,
949- textCapitalization: widget.textCapitalization,
950- style: style,
951- strutStyle: widget.strutStyle,
952- textAlign: widget.textAlign,
953- textDirection: widget.textDirection,
954- autofocus: widget.autofocus,
955- obscureText: widget.obscureText,
956- autocorrect: widget.autocorrect,
957- maxLines: widget.maxLines,
958- minLines: widget.minLines,
959- expands: widget.expands,
960- selectionColor: themeData.textSelectionColor,
961- selectionControls: widget.selectionEnabled ? textSelectionControls : null ,
962- onChanged: widget.onChanged,
963- onSelectionChanged: _handleSelectionChanged,
964- onEditingComplete: widget.onEditingComplete,
965- onSubmitted: widget.onSubmitted,
966- onSelectionHandleTapped: _handleSelectionHandleTapped,
967- inputFormatters: formatters,
968- rendererIgnoresPointer: true ,
969- cursorWidth: widget.cursorWidth,
970- cursorRadius: cursorRadius,
971- cursorColor: cursorColor,
972- cursorOpacityAnimates: cursorOpacityAnimates,
973- cursorOffset: cursorOffset,
974- paintCursorAboveText: paintCursorAboveText,
975- backgroundCursorColor: CupertinoColors .inactiveGray,
976- scrollPadding: widget.scrollPadding,
977- keyboardAppearance: keyboardAppearance,
978- enableInteractiveSelection: widget.enableInteractiveSelection,
979- dragStartBehavior: widget.dragStartBehavior,
980- scrollController: widget.scrollController,
981- scrollPhysics: widget.scrollPhysics,
950+ child: Shortcuts (
951+ shortcuts: _disabledNavigationKeys,
952+ child: EditableText (
953+ key: editableTextKey,
954+ readOnly: widget.readOnly,
955+ toolbarOptions: widget.toolbarOptions,
956+ showCursor: widget.showCursor,
957+ showSelectionHandles: _showSelectionHandles,
958+ controller: controller,
959+ focusNode: focusNode,
960+ keyboardType: widget.keyboardType,
961+ textInputAction: widget.textInputAction,
962+ textCapitalization: widget.textCapitalization,
963+ style: style,
964+ strutStyle: widget.strutStyle,
965+ textAlign: widget.textAlign,
966+ textDirection: widget.textDirection,
967+ autofocus: widget.autofocus,
968+ obscureText: widget.obscureText,
969+ autocorrect: widget.autocorrect,
970+ maxLines: widget.maxLines,
971+ minLines: widget.minLines,
972+ expands: widget.expands,
973+ selectionColor: themeData.textSelectionColor,
974+ selectionControls: widget.selectionEnabled ? textSelectionControls : null ,
975+ onChanged: widget.onChanged,
976+ onSelectionChanged: _handleSelectionChanged,
977+ onEditingComplete: widget.onEditingComplete,
978+ onSubmitted: widget.onSubmitted,
979+ onSelectionHandleTapped: _handleSelectionHandleTapped,
980+ inputFormatters: formatters,
981+ rendererIgnoresPointer: true ,
982+ cursorWidth: widget.cursorWidth,
983+ cursorRadius: cursorRadius,
984+ cursorColor: cursorColor,
985+ cursorOpacityAnimates: cursorOpacityAnimates,
986+ cursorOffset: cursorOffset,
987+ paintCursorAboveText: paintCursorAboveText,
988+ backgroundCursorColor: CupertinoColors .inactiveGray,
989+ scrollPadding: widget.scrollPadding,
990+ keyboardAppearance: keyboardAppearance,
991+ enableInteractiveSelection: widget.enableInteractiveSelection,
992+ dragStartBehavior: widget.dragStartBehavior,
993+ scrollController: widget.scrollController,
994+ scrollPhysics: widget.scrollPhysics,
995+ ),
982996 ),
983997 );
984998
0 commit comments