Unverified Commit 9375377f authored by Matthew Cliatt's avatar Matthew Cliatt Committed by GitHub

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.
parent 406d8f7f
......@@ -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 {
......
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