Unverified Commit d9a69e3b authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Desktop keys: up/down + line modifier (#74425)

up/down arrows + cmd (optionally + shift) works on desktop to jump selection to beginning/end of field
parent 35b9288e
......@@ -712,6 +712,29 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
// case where the user moves the cursor to the end or beginning of the text
// and then back up or down.
if (downArrow || upArrow) {
if (lineModifier) {
if (upArrow) {
// Extend the selection to the beginning of the field.
final int upperOffset = math.max(0, math.max(
newSelection.baseOffset,
newSelection.extentOffset,
));
newSelection = TextSelection(
baseOffset: shift ? upperOffset : 0,
extentOffset: 0,
);
} else {
// Extend the selection to the end of the field.
final int lowerOffset = math.max(0, math.min(
newSelection.baseOffset,
newSelection.extentOffset,
));
newSelection = TextSelection(
baseOffset: shift ? lowerOffset : _plainText.length,
extentOffset: _plainText.length,
);
}
} else {
// The caret offset gives a location in the upper left hand corner of
// the caret so the middle of the line above is a half line above that
// point and the line below is 1.5 lines below that point.
......@@ -741,6 +764,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
_cursorResetLocation = newSelection.extentOffset;
}
}
}
// Just place the collapsed selection at the end or beginning of the region
// if shift isn't down or selection isn't enabled.
......
......@@ -4167,6 +4167,144 @@ void main() {
reason: 'on $platform',
);
// Jump to end.
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.arrowDown,
],
shift: false,
lineModifier: true,
platform: platform,
);
expect(
selection,
equals(
const TextSelection.collapsed(
offset: testText.length,
affinity: TextAffinity.downstream,
),
),
reason: 'on $platform',
);
expect(controller.text, equals(testText), reason: 'on $platform');
// Jump to start.
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.arrowUp,
],
shift: false,
lineModifier: true,
platform: platform,
);
expect(
selection,
equals(
const TextSelection.collapsed(
offset: 0,
affinity: TextAffinity.downstream,
),
),
reason: 'on $platform',
);
expect(controller.text, equals(testText), reason: 'on $platform');
// Move forward a few letters
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.arrowRight,
LogicalKeyboardKey.arrowRight,
LogicalKeyboardKey.arrowRight,
],
shift: false,
lineModifier: false,
platform: platform,
);
expect(
selection,
equals(
const TextSelection.collapsed(
offset: 3,
affinity: TextAffinity.downstream,
),
),
reason: 'on $platform',
);
// Select to end.
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.arrowDown,
],
shift: true,
lineModifier: true,
platform: platform,
);
expect(
selection,
equals(
const TextSelection(
baseOffset: 3,
extentOffset: testText.length,
affinity: TextAffinity.downstream,
),
),
reason: 'on $platform',
);
// Select to start, which extends the selection.
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.arrowUp,
],
shift: true,
lineModifier: true,
platform: platform,
);
expect(
selection,
equals(
const TextSelection(
baseOffset: testText.length,
extentOffset: 0,
affinity: TextAffinity.downstream,
),
),
reason: 'on $platform',
);
// Move to start again.
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.arrowUp,
],
shift: false,
lineModifier: false,
platform: platform,
);
expect(
selection,
equals(
const TextSelection.collapsed(
offset: 0,
affinity: TextAffinity.downstream,
),
),
reason: 'on $platform',
);
// Jump forward three words.
await sendKeys(
tester,
......
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