Unverified Commit 75453e6a authored by Ricardo Canastro's avatar Ricardo Canastro Committed by GitHub

Support block delete with word and line modifiers (#77172)

parent 2369d76a
...@@ -36,6 +36,12 @@ class DefaultTextEditingActions extends Actions{ ...@@ -36,6 +36,12 @@ class DefaultTextEditingActions extends Actions{
// are called on which platform. // are called on which platform.
static final Map<Type, Action<Intent>> _shortcutsActions = <Type, Action<Intent>>{ static final Map<Type, Action<Intent>> _shortcutsActions = <Type, Action<Intent>>{
DoNothingAndStopPropagationTextIntent: _DoNothingAndStopPropagationTextAction(), DoNothingAndStopPropagationTextIntent: _DoNothingAndStopPropagationTextAction(),
DeleteTextIntent: _DeleteTextAction(),
DeleteByWordTextIntent: _DeleteByWordTextAction(),
DeleteByLineTextIntent: _DeleteByLineTextAction(),
DeleteForwardTextIntent: _DeleteForwardTextAction(),
DeleteForwardByWordTextIntent: _DeleteForwardByWordTextAction(),
DeleteForwardByLineTextIntent: _DeleteForwardByLineTextAction(),
ExtendSelectionDownTextIntent: _ExtendSelectionDownTextAction(), ExtendSelectionDownTextIntent: _ExtendSelectionDownTextAction(),
ExtendSelectionLeftByLineTextIntent: _ExtendSelectionLeftByLineTextAction(), ExtendSelectionLeftByLineTextIntent: _ExtendSelectionLeftByLineTextAction(),
ExtendSelectionLeftByWordTextIntent: _ExtendSelectionLeftByWordTextAction(), ExtendSelectionLeftByWordTextIntent: _ExtendSelectionLeftByWordTextAction(),
...@@ -76,6 +82,48 @@ class _DoNothingAndStopPropagationTextAction extends TextEditingAction<DoNothing ...@@ -76,6 +82,48 @@ class _DoNothingAndStopPropagationTextAction extends TextEditingAction<DoNothing
void invoke(DoNothingAndStopPropagationTextIntent intent, [BuildContext? context]) {} void invoke(DoNothingAndStopPropagationTextIntent intent, [BuildContext? context]) {}
} }
class _DeleteTextAction extends TextEditingAction<DeleteTextIntent> {
@override
Object? invoke(DeleteTextIntent intent, [BuildContext? context]) {
textEditingActionTarget!.renderEditable.delete(SelectionChangedCause.keyboard);
}
}
class _DeleteByWordTextAction extends TextEditingAction<DeleteByWordTextIntent> {
@override
Object? invoke(DeleteByWordTextIntent intent, [BuildContext? context]) {
textEditingActionTarget!.renderEditable.deleteByWord(SelectionChangedCause.keyboard, false);
}
}
class _DeleteByLineTextAction extends TextEditingAction<DeleteByLineTextIntent> {
@override
Object? invoke(DeleteByLineTextIntent intent, [BuildContext? context]) {
textEditingActionTarget!.renderEditable.deleteByLine(SelectionChangedCause.keyboard);
}
}
class _DeleteForwardTextAction extends TextEditingAction<DeleteForwardTextIntent> {
@override
Object? invoke(DeleteForwardTextIntent intent, [BuildContext? context]) {
textEditingActionTarget!.renderEditable.deleteForward(SelectionChangedCause.keyboard);
}
}
class _DeleteForwardByWordTextAction extends TextEditingAction<DeleteForwardByWordTextIntent> {
@override
Object? invoke(DeleteForwardByWordTextIntent intent, [BuildContext? context]) {
textEditingActionTarget!.renderEditable.deleteForwardByWord(SelectionChangedCause.keyboard, false);
}
}
class _DeleteForwardByLineTextAction extends TextEditingAction<DeleteForwardByLineTextIntent> {
@override
Object? invoke(DeleteForwardByLineTextIntent intent, [BuildContext? context]) {
textEditingActionTarget!.renderEditable.deleteForwardByLine(SelectionChangedCause.keyboard);
}
}
class _ExpandSelectionLeftByLineTextAction extends TextEditingAction<ExpandSelectionLeftByLineTextIntent> { class _ExpandSelectionLeftByLineTextAction extends TextEditingAction<ExpandSelectionLeftByLineTextIntent> {
@override @override
Object? invoke(ExpandSelectionLeftByLineTextIntent intent, [BuildContext? context]) { Object? invoke(ExpandSelectionLeftByLineTextIntent intent, [BuildContext? context]) {
......
...@@ -161,6 +161,12 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -161,6 +161,12 @@ class DefaultTextEditingShortcuts extends Shortcuts {
); );
static final Map<LogicalKeySet, Intent> _androidShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _androidShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DeleteTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.backspace): const DeleteByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DeleteByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DeleteForwardTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.delete): const DeleteForwardByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DeleteForwardByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(),
...@@ -195,9 +201,17 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -195,9 +201,17 @@ class DefaultTextEditingShortcuts extends Shortcuts {
// * Meta + shift + arrow up // * Meta + shift + arrow up
// * Shift + end // * Shift + end
// * Shift + home // * Shift + home
// * Meta + delete
// * Meta + backspace
}; };
static final Map<LogicalKeySet, Intent> _fuchsiaShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _fuchsiaShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DeleteTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.backspace): const DeleteByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DeleteByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DeleteForwardTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.delete): const DeleteForwardByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DeleteForwardByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(),
...@@ -232,9 +246,17 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -232,9 +246,17 @@ class DefaultTextEditingShortcuts extends Shortcuts {
// * Meta + shift + arrow up // * Meta + shift + arrow up
// * Shift + end // * Shift + end
// * Shift + home // * Shift + home
// * Meta + delete
// * Meta + backspace
}; };
static final Map<LogicalKeySet, Intent> _iOSShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _iOSShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DeleteTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.backspace): const DeleteByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DeleteByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DeleteForwardTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.delete): const DeleteForwardByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DeleteForwardByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(),
...@@ -269,9 +291,17 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -269,9 +291,17 @@ class DefaultTextEditingShortcuts extends Shortcuts {
// * Meta + shift + arrow up // * Meta + shift + arrow up
// * Shift + end // * Shift + end
// * Shift + home // * Shift + home
// * Meta + delete
// * Meta + backspace
}; };
static final Map<LogicalKeySet, Intent> _linuxShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _linuxShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DeleteTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.backspace): const DeleteByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DeleteByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DeleteForwardTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.delete): const DeleteForwardByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DeleteForwardByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(),
...@@ -306,9 +336,17 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -306,9 +336,17 @@ class DefaultTextEditingShortcuts extends Shortcuts {
// * Meta + shift + arrow up // * Meta + shift + arrow up
// * Shift + end // * Shift + end
// * Shift + home // * Shift + home
// * Meta + delete
// * Meta + backspace
}; };
static final Map<LogicalKeySet, Intent> _macShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _macShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DeleteTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DeleteByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.backspace): const DeleteByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DeleteForwardTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DeleteForwardByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.delete): const DeleteForwardByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionRightByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionRightByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByWordTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByWordTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByWordTextIntent(),
...@@ -343,9 +381,17 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -343,9 +381,17 @@ class DefaultTextEditingShortcuts extends Shortcuts {
// * Home // * Home
// * Shift + end // * Shift + end
// * Shift + home // * Shift + home
// * Control + delete
// * Control + backspace
}; };
static final Map<LogicalKeySet, Intent> _windowsShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _windowsShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DeleteTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.backspace): const DeleteByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DeleteByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DeleteForwardTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.delete): const DeleteForwardByWordTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DeleteForwardByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const MoveSelectionToEndTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const MoveSelectionLeftByLineTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const MoveSelectionRightByLineTextIntent(),
...@@ -380,11 +426,21 @@ class DefaultTextEditingShortcuts extends Shortcuts { ...@@ -380,11 +426,21 @@ class DefaultTextEditingShortcuts extends Shortcuts {
// * Meta + shift + arrow left // * Meta + shift + arrow left
// * Meta + shift + arrow right // * Meta + shift + arrow right
// * Meta + shift + arrow up // * Meta + shift + arrow up
// * Meta + delete
// * Meta + backspace
}; };
// Web handles its text selection natively and doesn't use any of these // Web handles its text selection natively and doesn't use any of these
// shortcuts in Flutter. // shortcuts in Flutter.
static final Map<LogicalKeySet, Intent> _webShortcuts = <LogicalKeySet, Intent>{ static final Map<LogicalKeySet, Intent> _webShortcuts = <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.backspace): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.delete): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.backspace): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.delete): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.backspace): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.delete): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.backspace): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.delete): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const DoNothingAndStopPropagationTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowDown): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const DoNothingAndStopPropagationTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowLeft): const DoNothingAndStopPropagationTextIntent(),
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const DoNothingAndStopPropagationTextIntent(), LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.arrowRight): const DoNothingAndStopPropagationTextIntent(),
......
...@@ -4,6 +4,54 @@ ...@@ -4,6 +4,54 @@
import 'actions.dart'; import 'actions.dart';
/// An [Intent] to delete a character in the backwards direction.
///
/// {@macro flutter.widgets.TextEditingIntents.seeAlso}
class DeleteTextIntent extends Intent{
/// Creates an instance of DeleteTextIntent.
const DeleteTextIntent();
}
/// An [Intent] to delete a word in the backwards direction.
///
/// {@macro flutter.widgets.TextEditingIntents.seeAlso}
class DeleteByWordTextIntent extends Intent{
/// Creates an instance of DeleteByWordTextIntent.
const DeleteByWordTextIntent();
}
/// An [Intent] to delete a line in the backwards direction.
///
/// {@macro flutter.widgets.TextEditingIntents.seeAlso}
class DeleteByLineTextIntent extends Intent{
/// Creates an instance of DeleteByLineTextIntent.
const DeleteByLineTextIntent();
}
/// An [Intent] to delete in the forward direction.
///
/// {@macro flutter.widgets.TextEditingIntents.seeAlso}
class DeleteForwardTextIntent extends Intent{
/// Creates an instance of DeleteForwardTextIntent.
const DeleteForwardTextIntent();
}
/// An [Intent] to delete a word in the forward direction.
///
/// {@macro flutter.widgets.TextEditingIntents.seeAlso}
class DeleteForwardByWordTextIntent extends Intent{
/// Creates an instance of DeleteByWordTextIntent.
const DeleteForwardByWordTextIntent();
}
/// An [Intent] to delete a line in the forward direction.
///
/// {@macro flutter.widgets.TextEditingIntents.seeAlso}
class DeleteForwardByLineTextIntent extends Intent{
/// Creates an instance of DeleteByLineTextIntent.
const DeleteForwardByLineTextIntent();
}
/// An [Intent] to send the event straight to the engine, but only if a /// An [Intent] to send the event straight to the engine, but only if a
/// TextEditingTarget is focused. /// TextEditingTarget is focused.
/// ///
......
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