Skip to content

Windows home/end shortcuts - #90840

Merged
justinmc merged 12 commits into
flutter:masterfrom
justinmc:windows-shortcuts-missing
Nov 23, 2021
Merged

justinmc merged 12 commits into
flutter:masterfrom
justinmc:windows-shortcuts-missing

Conversation

@justinmc

@justinmc justinmc commented Sep 27, 2021 •

Copy link
Copy Markdown
Contributor

This PR fixes some keyboard shortcuts on Windows that were missing/incorrect. From the issue, these were my observations before starting this PR:

Shortcut Behavior (Windows) Behavior (Flutter)
Ctrl+Home/End move to start/end of all text ❌ nothing
Ctrl+Shift+Home/End extend selection to start/end of all text ❌ nothing
Shift+Home/End extend selection to start/end of line ❌ works, but pauses at inversion, and jumps lines

Fixes #77020
I've opened a separate issue for the incorrect movement between lines: #90993

@justinmc justinmc self-assigned this Sep 27, 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 Sep 27, 2021
@google-cla google-cla Bot added the cla: yes label Sep 27, 2021
@justinmc

Copy link
Copy Markdown
Contributor Author

@LongCatIsLooong FYI this is going to conflict with your refactor #90684. I'm still working on this a bit so maybe I should just wait until your PR is merged and then make these changes in the new pattern.

@justinmc justinmc changed the title (WIP) Windows home/end shortcuts Windows home/end shortcuts Sep 29, 2021
@justinmc
justinmc marked this pull request as ready for review September 29, 2021 22:18
@goderbauer

Copy link
Copy Markdown
Member

From triage: Looks like #90684 is submitted now 🥳

@justinmc

Copy link
Copy Markdown
Contributor Author

Will update this, thanks!

@justinmc
justinmc force-pushed the windows-shortcuts-missing branch from cda763a to 1b53858 Compare November 11, 2021 00:59
? TextSelection.fromPosition(newExtent)
: textBoundarySelection.extendTo(newExtent);

// If collapseAtReversal is true and would have an effect, collapse it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@LongCatIsLooong How would you prefer that we implement this "collapseAtReversal" feature within your new Actions setup? Feel free to butcher this if it's totally off, I'm still getting the hang of your new refactor so I've just put down a quick attempt.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah this makes sense to me!

SingleActivator(LogicalKeyboardKey.end): ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: true),
SingleActivator(LogicalKeyboardKey.home, shift: true): ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false),
SingleActivator(LogicalKeyboardKey.end, shift: true): ExtendSelectionToLineBreakIntent(forward: true, collapseSelection: false),
SingleActivator(LogicalKeyboardKey.home, shift: true): ExtendSelectionToLineBreakIntent(forward: false, collapseSelection: false, collapseAtReversal: true),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tried on windows 10, it doesn't seem to collapse at reversal? E.g., the initial selection is aaaaaa|bbbbb, I pressed shift-End it became aaaaaa<bbbbb> and then I pressed shift-Home it became <aaaaaa>bbbbb. This was tested in the explorer's address bar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks good catch. My table in the description of this PR is correct, but I got this code backwards when I ported it. I've fixed it.

I also double checked Linux (gedit). It has the same behavior as Windows.

@justinmc

Copy link
Copy Markdown
Contributor Author

@LongCatIsLooong In need of a re-review when you have a chance.

// * Meta + backspace
static const Map<ShortcutActivator, Intent> _windowsShortcuts = _linuxShortcuts;
static const Map<ShortcutActivator, Intent> _windowsShortcuts = <ShortcutActivator, Intent>{
..._linuxShortcuts,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: _commonShortcuts is the same as _linuxShortcuts iirc? I probably should have referenced _commonShortcuts here it's a bit confusing why we are including _linuxShortcuts for windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've reworked this to just use ..._commonShortcuts here. I had to duplicate 4 entries but I think that's fine.

SingleActivator(LogicalKeyboardKey.arrowUp, shift: true): DoNothingAndStopPropagationTextIntent(),
SingleActivator(LogicalKeyboardKey.end, shift: true): DoNothingAndStopPropagationTextIntent(),
SingleActivator(LogicalKeyboardKey.home, shift: true): DoNothingAndStopPropagationTextIntent(),
SingleActivator(LogicalKeyboardKey.end, control: true): DoNothingAndStopPropagationTextIntent(),

@LongCatIsLooong LongCatIsLooong Nov 22, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something related but doesn't have to be addressed in the pull request: would it be possible if we create a Map subclass that always returns DoNothingAndStopPropagationTextIntent? Or is it possible we relax what the Shortcuts widget use for Intent lookup, so it takes a function of type ShortcutActivator => Intent (instead of a Map)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that might help us avoid a lot of this code. @gspencergoog Do you have any opinion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could make a different constructor for Shortcuts that takes a function instead of a Map. I'd want to keep the one that takes a Map, though. One additional benefit of the function over the map would be that it might be faster to construct: long maps can get slow to construct on each build.

@justinmc justinmc Dec 4, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That would work, so all of this _webShortcuts map would just be a check for kIsWeb and if so return DoNothingAndStopPropagationTextIntent. I'll keep this in mind next time I'm working on this code.

? TextSelection.fromPosition(newExtent)
: textBoundarySelection.extendTo(newExtent);

// If collapseAtReversal is true and would have an effect, collapse it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah this makes sense to me!

),
));

// Focus on the EditableText, which is a TextEditingActionTarget.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought I removed this file, since TextEditingActionTarget is gone?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So did I but I also noticed that text_editing_action_target.dart was still in the repo unused! I removed it in this PR. Maybe it accidentally came back in a merge or something and we missed it?

I went ahead and deleted this test file too now.

@justinmc
justinmc merged commit a1115b8 into flutter:master Nov 23, 2021
@justinmc
justinmc deleted the windows-shortcuts-missing branch November 23, 2021 22:49
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.

TextField: Missing keyboard shortcuts for Windows

4 participants