Unverified Commit 7f4bb1ee authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

Use the shortcuts temporary solution only on web (#74768)

parent 7c0300a3
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
import 'package:flutter/foundation.dart' show defaultTargetPlatform; import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb;
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -1201,32 +1201,37 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio ...@@ -1201,32 +1201,37 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
), ),
); );
return Shortcuts( final Widget child = Semantics(
shortcuts: scrollShortcutOverrides, enabled: enabled,
child: Semantics( onTap: !enabled || widget.readOnly ? null : () {
enabled: enabled, if (!controller.selection.isValid) {
onTap: !enabled || widget.readOnly ? null : () { controller.selection = TextSelection.collapsed(offset: controller.text.length);
if (!controller.selection.isValid) { }
controller.selection = TextSelection.collapsed(offset: controller.text.length); _requestKeyboard();
} },
_requestKeyboard(); child: IgnorePointer(
}, ignoring: !enabled,
child: IgnorePointer( child: Container(
ignoring: !enabled, decoration: effectiveDecoration,
child: Container( child: _selectionGestureDetectorBuilder.buildGestureDetector(
decoration: effectiveDecoration, behavior: HitTestBehavior.translucent,
child: _selectionGestureDetectorBuilder.buildGestureDetector( child: Align(
behavior: HitTestBehavior.translucent, alignment: Alignment(-1.0, _textAlignVertical.y),
child: Align( widthFactor: 1.0,
alignment: Alignment(-1.0, _textAlignVertical.y), heightFactor: 1.0,
widthFactor: 1.0, child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle),
heightFactor: 1.0,
child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle),
),
), ),
), ),
), ),
), ),
); );
if (kIsWeb) {
return Shortcuts(
shortcuts: scrollShortcutOverrides,
child: child,
);
}
return child;
} }
} }
...@@ -1290,35 +1290,40 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1290,35 +1290,40 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
semanticsMaxValueLength = null; semanticsMaxValueLength = null;
} }
return MouseRegion( child = MouseRegion(
cursor: effectiveMouseCursor, cursor: effectiveMouseCursor,
onEnter: (PointerEnterEvent event) => _handleHover(true), onEnter: (PointerEnterEvent event) => _handleHover(true),
onExit: (PointerExitEvent event) => _handleHover(false), onExit: (PointerExitEvent event) => _handleHover(false),
child: Shortcuts( child: IgnorePointer(
shortcuts: scrollShortcutOverrides, ignoring: !_isEnabled,
child: IgnorePointer( child: AnimatedBuilder(
ignoring: !_isEnabled, animation: controller, // changes the _currentLength
child: AnimatedBuilder( builder: (BuildContext context, Widget? child) {
animation: controller, // changes the _currentLength return Semantics(
builder: (BuildContext context, Widget? child) { maxValueLength: semanticsMaxValueLength,
return Semantics( currentValueLength: _currentLength,
maxValueLength: semanticsMaxValueLength, onTap: widget.readOnly ? null : () {
currentValueLength: _currentLength, if (!_effectiveController.selection.isValid)
onTap: widget.readOnly ? null : () { _effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length);
if (!_effectiveController.selection.isValid) _requestKeyboard();
_effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length); },
_requestKeyboard();
},
child: child,
);
},
child: _selectionGestureDetectorBuilder.buildGestureDetector(
behavior: HitTestBehavior.translucent,
child: child, child: child,
), );
},
child: _selectionGestureDetectorBuilder.buildGestureDetector(
behavior: HitTestBehavior.translucent,
child: child,
), ),
), ),
), ),
); );
if (kIsWeb) {
return Shortcuts(
shortcuts: scrollShortcutOverrides,
child: child,
);
}
return child;
} }
} }
...@@ -58,15 +58,13 @@ const int _kObscureShowLatestCharCursorTicks = 3; ...@@ -58,15 +58,13 @@ const int _kObscureShowLatestCharCursorTicks = 3;
/// A map used to disable scrolling shortcuts in text fields. /// A map used to disable scrolling shortcuts in text fields.
/// ///
/// This is a temporary fix for: https://github.com/flutter/flutter/issues/74191 /// This is a temporary fix for: https://github.com/flutter/flutter/issues/74191
final Map<LogicalKeySet, Intent> scrollShortcutOverrides = kIsWeb final Map<LogicalKeySet, Intent> scrollShortcutOverrides = <LogicalKeySet, Intent>{
? <LogicalKeySet, Intent>{ LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(), LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(), LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(), LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(), LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(), };
}
: <LogicalKeySet, Intent>{};
/// A controller for an editable text field. /// A controller for an editable text field.
/// ///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment