Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Dec 29, 2021

Command + shift + left/right arrow should expand to the beginning/end of the line, not extend or pivot like other platforms.

Mac single line

words |words words
=>
words |words words|
<=
|words words words|

Other platforms single line

words |words words
=>
words |words words|
<=
|words |words words

Mac multi line

words |words words
words |words words
=>
words |words words
words words words|
<=
|words words words
words words words|

Mac single line

words |words words
=>
words |words words|
<=
|words words words|

Other platforms multi line

words |words words
words |words words
=>
words |words words
words words words|
<=
|words words words
|words words words

Fixes #93883 (comment)

@justinmc justinmc self-assigned this Dec 29, 2021
@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Dec 29, 2021
@justinmc justinmc force-pushed the mac-expand-to-linebreak branch from 2f10e2e to 5136086 Compare December 29, 2021 23:48
@justinmc justinmc marked this pull request as ready for review December 30, 2021 00:24

const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false),
const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, meta: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: false),
const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false, expand: true),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LongCatIsLooong What do you think of adding this expand parameter here, or would it be better to do something like creating an all new intent?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable, but I would slightly prefer having a different intent since collapseSelection and expand can't both be true and currently it relies on a run time assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've created a new Intent as a subclass of DirectionalTextEditingIntent and I think it worked out cleaner 👍 .

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

LGTM with nits

}

final TextPosition extent = textBoundarySelection.extent;
late final TextPosition position;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is the late needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undone with refactoring to use a new Intent.

/// be held in place while the extent is moved.
///
/// When set to true, the selection will expand, meaning that the selection
/// will grow by moving either the base or the extent.
Copy link
Contributor

Choose a reason for hiding this comment

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

"whichever is closest to the target location" or something similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also maybe say this is typically only for macOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exact comment was removed because I created a separate Intent. I made sure that Intent's comments were clear and I added a line about MacOS there.

final TextSelection newSelection = collapseSelection
? TextSelection.fromPosition(newExtent)
: textBoundarySelection.extendTo(newExtent);
late final TextSelection newSelection;
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary late?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undone with refactoring to use a new Intent.

if (collapseSelection) {
newSelection = TextSelection.fromPosition(newExtent);
} else {
newSelection = intent.expand
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried this and it seems macos does not move the extent when it expands the selection? cmd+shift+-> and then press -> the cursor moves to 1 character to the right from its original position.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I've got this right now, the behavior might have changed since you tested it. Here's what I'm testing that seems to match with TextEdit:

  • With cursor in the middle of the line, cmd + left. Left end is the extent.
  • With cursor in the middle of the line, cmd + right. Right end is the extent.
  • With cursor in the middle of the line, cmd + left then cmd + right. Left end is the extent.
  • With cursor in the middle of the line, cmd + right then cmd + left. Right end is the extent.
  • With an RTL selection in the middle of the line, cmd + left. Left end is the extent.
  • With an RTL selection in the middle of the line, cmd + right. Left end is the extent.
  • With an LTR selection in the middle of the line, cmd + right. Right end is the extent.
  • With an LTR selection in the middle of the line, cmd + left. Right end is the extent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just added tests for all of these cases too. By "testing" in the previous comment I meant manually trying myself vs. TextEdit.


const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false),
const SingleActivator(LogicalKeyboardKey.arrowRight, shift: true, meta: true): const ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: false),
const SingleActivator(LogicalKeyboardKey.arrowLeft, shift: true, meta: true): const ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false, expand: true),
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems reasonable, but I would slightly prefer having a different intent since collapseSelection and expand can't both be true and currently it relies on a run time assert.

@justinmc justinmc force-pushed the mac-expand-to-linebreak branch from d10f76e to fa01357 Compare January 11, 2022 23:46
@fluttergithubbot fluttergithubbot merged commit 8b46014 into flutter:master Jan 13, 2022
@justinmc justinmc deleted the mac-expand-to-linebreak branch January 13, 2022 22:30
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jan 18, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jan 18, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jan 18, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 4, 2022
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
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.

Mac cmd + shift + arrow expand behavior

3 participants