Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/rendering/editable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions packages/flutter/test/rendering/editable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,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.

Expand All @@ -896,21 +897,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);
Expand All @@ -920,9 +925,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 {
Expand Down