mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix handling backspace on macos with text selection (#49760)
Fixes #46150 by catching both the delete and backspace keys, rather than just the delete key.
This commit is contained in:
parent
406d8f7f1e
commit
9375377fa9
@ -431,12 +431,17 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
LogicalKeyboardKey.arrowDown,
|
||||
};
|
||||
|
||||
static final Set<LogicalKeyboardKey> _deleteKeys = <LogicalKeyboardKey>{
|
||||
LogicalKeyboardKey.delete,
|
||||
LogicalKeyboardKey.backspace,
|
||||
};
|
||||
|
||||
static final Set<LogicalKeyboardKey> _shortcutKeys = <LogicalKeyboardKey>{
|
||||
LogicalKeyboardKey.keyA,
|
||||
LogicalKeyboardKey.keyC,
|
||||
LogicalKeyboardKey.keyV,
|
||||
LogicalKeyboardKey.keyX,
|
||||
LogicalKeyboardKey.delete,
|
||||
..._deleteKeys,
|
||||
};
|
||||
|
||||
static final Set<LogicalKeyboardKey> _nonModifierKeys = <LogicalKeyboardKey>{
|
||||
@ -491,7 +496,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
// _handleShortcuts depends on being started in the same stack invocation
|
||||
// as the _handleKeyEvent method
|
||||
_handleShortcuts(key);
|
||||
} else if (key == LogicalKeyboardKey.delete) {
|
||||
} else if (_deleteKeys.contains(key)) {
|
||||
_handleDelete();
|
||||
}
|
||||
}
|
||||
|
@ -3738,6 +3738,51 @@ void main() {
|
||||
reason: 'on $platform',
|
||||
);
|
||||
expect(controller.text, isEmpty, reason: 'on $platform');
|
||||
|
||||
/// Paste and Select All
|
||||
await sendKeys(
|
||||
tester,
|
||||
<LogicalKeyboardKey>[
|
||||
LogicalKeyboardKey.keyV,
|
||||
LogicalKeyboardKey.keyA,
|
||||
],
|
||||
shortcutModifier: true,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
expect(
|
||||
selection,
|
||||
equals(
|
||||
const TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: testText.length,
|
||||
affinity: TextAffinity.downstream,
|
||||
),
|
||||
),
|
||||
reason: 'on $platform',
|
||||
);
|
||||
expect(controller.text, equals(testText), reason: 'on $platform');
|
||||
|
||||
// Backspace
|
||||
await sendKeys(
|
||||
tester,
|
||||
<LogicalKeyboardKey>[
|
||||
LogicalKeyboardKey.delete,
|
||||
],
|
||||
platform: platform,
|
||||
);
|
||||
expect(
|
||||
selection,
|
||||
equals(
|
||||
const TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: 72,
|
||||
affinity: TextAffinity.downstream,
|
||||
),
|
||||
),
|
||||
reason: 'on $platform',
|
||||
);
|
||||
expect(controller.text, isEmpty, reason: 'on $platform');
|
||||
}
|
||||
|
||||
testWidgets('keyboard text selection works as expected on linux', (WidgetTester tester) async {
|
||||
|
Loading…
Reference in New Issue
Block a user