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

Explicitly set affinity when moving left/right by line (#87133)

parent a7899c19
...@@ -1965,6 +1965,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ...@@ -1965,6 +1965,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint)); final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));
final TextSelection nextSelection = TextSelection.collapsed( final TextSelection nextSelection = TextSelection.collapsed(
offset: selectedLine.baseOffset, offset: selectedLine.baseOffset,
affinity: TextAffinity.downstream,
); );
_setSelection(nextSelection, cause); _setSelection(nextSelection, cause);
...@@ -2051,6 +2052,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ...@@ -2051,6 +2052,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint)); final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));
final TextSelection nextSelection = TextSelection.collapsed( final TextSelection nextSelection = TextSelection.collapsed(
offset: selectedLine.extentOffset, offset: selectedLine.extentOffset,
affinity: TextAffinity.upstream,
); );
_setSelection(nextSelection, cause); _setSelection(nextSelection, cause);
......
...@@ -925,6 +925,7 @@ void main() { ...@@ -925,6 +925,7 @@ void main() {
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard); editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 13); expect(currentSelection.baseOffset, 13);
expect(currentSelection.affinity, TextAffinity.upstream);
// RenderEditable relies on its parent that passes onSelectionChanged to set // RenderEditable relies on its parent that passes onSelectionChanged to set
// the selection. // the selection.
...@@ -933,21 +934,25 @@ void main() { ...@@ -933,21 +934,25 @@ void main() {
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard); editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 13); expect(currentSelection.baseOffset, 13);
expect(currentSelection.affinity, TextAffinity.upstream);
// Move back to the start of the line. // Move back to the start of the line.
editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard); editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 0); expect(currentSelection.baseOffset, 0);
expect(currentSelection.affinity, TextAffinity.downstream);
// Trying moveSelectionLeftByLine does nothing at the leftmost of the field. // Trying moveSelectionLeftByLine does nothing at the leftmost of the field.
editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard); editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 0); expect(currentSelection.baseOffset, 0);
expect(currentSelection.affinity, TextAffinity.downstream);
// Move the selection to the empty line. // Move the selection to the empty line.
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard); editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 13); expect(currentSelection.baseOffset, 13);
expect(currentSelection.affinity, TextAffinity.upstream);
editable.moveSelectionRight(SelectionChangedCause.keyboard); editable.moveSelectionRight(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 14); expect(currentSelection.baseOffset, 14);
...@@ -957,9 +962,11 @@ void main() { ...@@ -957,9 +962,11 @@ void main() {
editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard); editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 14); expect(currentSelection.baseOffset, 14);
expect(currentSelection.affinity, TextAffinity.downstream);
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard); editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
expect(currentSelection.isCollapsed, true); expect(currentSelection.isCollapsed, true);
expect(currentSelection.baseOffset, 14); expect(currentSelection.baseOffset, 14);
expect(currentSelection.affinity, TextAffinity.downstream);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021 }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021
test('arrow keys and delete handle simple text correctly', () async { test('arrow keys and delete handle simple text correctly', () 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