[web] Fix text field shortcuts when inside a scroll area (#79051)
This commit is contained in:
parent
ef7258d66d
commit
e03ccd62ae
@ -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';
|
||||||
@ -18,6 +18,16 @@ import 'theme.dart';
|
|||||||
|
|
||||||
export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType;
|
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(
|
const TextStyle _kDefaultPlaceholderStyle = TextStyle(
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
color: CupertinoColors.placeholderText,
|
color: CupertinoColors.placeholderText,
|
||||||
@ -1212,7 +1222,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Semantics(
|
final Widget child = Semantics(
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
onTap: !enabled || widget.readOnly ? null : () {
|
onTap: !enabled || widget.readOnly ? null : () {
|
||||||
if (!controller.selection.isValid) {
|
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;
|
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.
|
/// Signature for the [TextField.buildCounter] callback.
|
||||||
typedef InputCounterWidgetBuilder = Widget? Function(
|
typedef InputCounterWidgetBuilder = Widget? Function(
|
||||||
/// The build context for the TextField.
|
/// The build context for the TextField.
|
||||||
@ -1301,7 +1311,7 @@ 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),
|
||||||
@ -1329,5 +1339,13 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (kIsWeb) {
|
||||||
|
return Shortcuts(
|
||||||
|
shortcuts: _webScrollShortcutOverrides,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user