Explicitly set affinity when moving left/right by line (#87133)
This commit is contained in:
committed by
GitHub
parent
a7899c1961
commit
c5866c5e20
@@ -1965,6 +1965,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||
final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));
|
||||
final TextSelection nextSelection = TextSelection.collapsed(
|
||||
offset: selectedLine.baseOffset,
|
||||
affinity: TextAffinity.downstream,
|
||||
);
|
||||
|
||||
_setSelection(nextSelection, cause);
|
||||
@@ -2051,6 +2052,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||
final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));
|
||||
final TextSelection nextSelection = TextSelection.collapsed(
|
||||
offset: selectedLine.extentOffset,
|
||||
affinity: TextAffinity.upstream,
|
||||
);
|
||||
|
||||
_setSelection(nextSelection, cause);
|
||||
|
||||
@@ -925,6 +925,7 @@ void main() {
|
||||
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 13);
|
||||
expect(currentSelection.affinity, TextAffinity.upstream);
|
||||
// RenderEditable relies on its parent that passes onSelectionChanged to set
|
||||
// the selection.
|
||||
|
||||
@@ -933,21 +934,25 @@ void main() {
|
||||
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 13);
|
||||
expect(currentSelection.affinity, TextAffinity.upstream);
|
||||
|
||||
// Move back to the start of the line.
|
||||
editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 0);
|
||||
expect(currentSelection.affinity, TextAffinity.downstream);
|
||||
|
||||
// Trying moveSelectionLeftByLine does nothing at the leftmost of the field.
|
||||
editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 0);
|
||||
expect(currentSelection.affinity, TextAffinity.downstream);
|
||||
|
||||
// Move the selection to the empty line.
|
||||
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 13);
|
||||
expect(currentSelection.affinity, TextAffinity.upstream);
|
||||
editable.moveSelectionRight(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 14);
|
||||
@@ -957,9 +962,11 @@ void main() {
|
||||
editable.moveSelectionLeftByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 14);
|
||||
expect(currentSelection.affinity, TextAffinity.downstream);
|
||||
editable.moveSelectionRightByLine(SelectionChangedCause.keyboard);
|
||||
expect(currentSelection.isCollapsed, true);
|
||||
expect(currentSelection.baseOffset, 14);
|
||||
expect(currentSelection.affinity, TextAffinity.downstream);
|
||||
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021
|
||||
|
||||
test('arrow keys and delete handle simple text correctly', () async {
|
||||
|
||||
Reference in New Issue
Block a user