Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Jun 30, 2021

Expanding by line (e.g. cmd-shift-left/right) shouldn't jump between lines when hit multiple times. According to my testing on native, it should go to the start/end of the line, and subsequent presses should do nothing. This PR matches that behavior and fixes some other sketchiness around the edges of lines, thanks to the engine bugfix referenced below.

After the PR it seems to work properly:

wordwrap

Fixes #79291
Depends on flutter/engine#28008

@justinmc justinmc requested a review from LongCatIsLooong June 30, 2021 21:27
@justinmc justinmc self-assigned this Jun 30, 2021
@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Jun 30, 2021
@google-cla google-cla bot added the cla: yes label Jun 30, 2021
@justinmc justinmc marked this pull request as draft June 30, 2021 21:51
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is selection.end right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like selection can be invalid here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the problem be we're initializing a new TextPosition with the default text affinity being downstream? If text affinity is upstream then _getLineAtOffset won't go to the next line right?

@goderbauer
Copy link
Member

(PR triage): @justinmc Do you still have plans for this PR?

@justinmc
Copy link
Contributor Author

justinmc commented Aug 2, 2021

@goderbauer Yes I do! I was waiting for #87133 to be merged. Coming back to this this week now.

@justinmc
Copy link
Contributor Author

This is blocked on flutter/engine#28008. There is a bug in the engine that should be fixed before this is fixed here, otherwise I'd be hacking around a bug.

@justinmc justinmc changed the title Expanding selection by line shouldn't go to the next line Keyboard text selection and wordwrap Aug 12, 2021
@justinmc justinmc force-pushed the expand-selection-by-line-inconsistency branch from e5564a6 to 74b8943 Compare August 13, 2021 01:13
@justinmc
Copy link
Contributor Author

Squashed commits in order to fix svg test.

@justinmc
Copy link
Contributor Author

@LongCatIsLooong Ready for re-review. This bumps into the problem of not having multiple TextAffinities for a non-collapsed TextSelection, which you mentioned here and I wrote up in #88135. I think this PR works in all practical situations though, which I've covered in my test, even though we're not able to distinguish certain non-collapsed selections.

@Piinks Piinks added the a: text input Entering text in a text field or keyboard related problems label Aug 17, 2021

// If the lowest edge of the selection is at the start of a line, don't do
// anything.
final int lowestOffset = math.min(selection!.baseOffset, selection!.extentOffset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is start. also we're doing the same thing in 1760.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines seem to be doing the same as line 1760-1762?

@justinmc
Copy link
Contributor Author

@LongCatIsLooong Ready for re-review. I've updated it to use start/end, but ran into the bug again of not having affinities for those points when not collapsed. I think I've worked around it in a way that still behaves as expected, and I tested two new cases.

return;
}

final int startPoint = previousCharacter(selection!.start, _plainText, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? Isn't currentLine already the first line of the current selection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I was able to get rid of it. The previousCharacter thing seems to have been used to work around these wordwrap problems mainly when getLineBoundary didn't respect TextAffinity.

@justinmc justinmc force-pushed the expand-selection-by-line-inconsistency branch from 6c9df75 to 86629c6 Compare August 26, 2021 22:05
offset: selection!.start,
affinity: selection!.isCollapsed ? selection!.affinity : TextAffinity.downstream,
));
if (currentLine.baseOffset == selection!.start) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to explicitly check here whether selection.start == currentLine.baseOffset? It seems 1763-1771 already covered that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this line, it would call _setSelection with a selection identical to the existing one, which can have side effects as it is written right now. I've previously been thinking about changing _setSelection so that it checks for equality and just returns if a change isn't needed, but that seems to break some things that rely on that behavior.

@justinmc justinmc merged commit b2adffa into flutter:master Aug 27, 2021
@justinmc justinmc deleted the expand-selection-by-line-inconsistency branch August 27, 2021 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MacOS move selection by line inconsistency

4 participants