Unverified Commit e03ccd62 authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Fix text field shortcuts when inside a scroll area (#79051)

parent ef7258d6
......@@ -4,7 +4,7 @@
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/rendering.dart';
import 'package:flutter/services.dart';
......@@ -18,6 +18,16 @@ import 'theme.dart';
export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType;
// This is a temporary fix for: https://github.com/flutter/flutter/issues/79012
/// A map used to disable scrolling shortcuts in text fields.
final Map<LogicalKeySet, Intent> _webScrollShortcutOverrides = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(),
};
const TextStyle _kDefaultPlaceholderStyle = TextStyle(
fontWeight: FontWeight.w400,
color: CupertinoColors.placeholderText,
......@@ -1212,7 +1222,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
),
);
return Semantics(
final Widget child = Semantics(
enabled: enabled,
onTap: !enabled || widget.readOnly ? null : () {
if (!controller.selection.isValid) {
......@@ -1238,5 +1248,13 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
),
),
);
if (kIsWeb) {
return Shortcuts(
shortcuts: _webScrollShortcutOverrides,
child: child,
);
}
return child;
}
}
......@@ -24,6 +24,16 @@ import 'theme.dart';
export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType;
// This is a temporary fix for: https://github.com/flutter/flutter/issues/79012
/// A map used to disable scrolling shortcuts in text fields.
final Map<LogicalKeySet, Intent> _webScrollShortcutOverrides = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(),
};
/// Signature for the [TextField.buildCounter] callback.
typedef InputCounterWidgetBuilder = Widget? Function(
/// The build context for the TextField.
......@@ -1301,7 +1311,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
semanticsMaxValueLength = null;
}
return MouseRegion(
child = MouseRegion(
cursor: effectiveMouseCursor,
onEnter: (PointerEnterEvent event) => _handleHover(true),
onExit: (PointerExitEvent event) => _handleHover(false),
......@@ -1329,5 +1339,13 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
),
),
);
if (kIsWeb) {
return Shortcuts(
shortcuts: _webScrollShortcutOverrides,
child: child,
);
}
return child;
}
}
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