Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selection marker overlays for keyboard selection #10865

Merged
merged 12 commits into from
Jun 20, 2022

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented Aug 3, 2021

Summary of the Pull Request

This introduces a selection marker overlay that tells the user which endpoint is currently being moved by the keyboard. The selection markers are respect font size changes and cursor color.

References

#715 - Keyboard Selection
#2840 - Keyboard Selection Spec
#5804 - Mark Mode Spec

Detailed Description of the Pull Request / Additional comments

  • TermControl layer:
    • Use a canvas (similar to the one used for hyperlinks) to be able to draw the selection markers.
    • If we are notified that the selection changed, update the selection markers appropriately.
    • UpdateSelectionMarkersEventArgs lets us distinguish between mouse and keyboard selections. ClearMarkers is set to true in the following cases...
      1. Mouse selection, via SetEndSelectionPoint
      2. LeftClickOnTerminal, pretty self-explanatory
      3. a selection created from searching for text
  • ControlCore layer:
    • Responsible for notifying TermControl to update the selection markers when a selection has changed.
    • Transfers info (the selection endpoint positions and which endpoint we're moving) from the terminal core to the term control.
  • TerminalCore layer:
    • Provides the viewport position of the selection endpoints.

Validation Steps Performed

  • mouse selection (w/ and w/out shift) --> no markers
  • keyboard selection --> markers
  • markers update appropriately when we pivot the selection
  • markers scroll when you hit a boundary
  • markers take the color of the cursor color setting
  • markers are resized when the font size changes

@DHowett

This comment was marked as outdated.

@github-actions

This comment has been minimized.

@zadjii-msft

This comment was marked as outdated.

@carlos-zamora

This comment was marked as outdated.

@carlos-zamora

This comment was marked as outdated.

@carlos-zamora carlos-zamora marked this pull request as draft August 4, 2021 16:58
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/keyboard-selection branch from 5b4dd33 to b2a7a19 Compare August 18, 2021 23:20
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/keyboard-selection branch from 5297b80 to 0cc9bd0 Compare September 2, 2021 22:04
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/keyboard-selection branch 2 times, most recently from e498dea to 118d1cd Compare September 17, 2021 02:58
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/ks/copy-mode branch from 2c52439 to ad26780 Compare September 23, 2021 19:23
Base automatically changed from dev/cazamor/keyboard-selection to main September 23, 2021 19:24
@zadjii-msft zadjii-msft added this to the Terminal v1.15 milestone Apr 12, 2022
@carlos-zamora carlos-zamora mentioned this pull request May 9, 2022
10 tasks
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/ks/copy-mode branch from ad26780 to 25d14ae Compare June 2, 2022 17:41
@microsoft microsoft deleted a comment from github-actions bot Jun 2, 2022
@github-actions

This comment was marked as resolved.

@carlos-zamora
Copy link
Member Author

carlos-zamora commented Jun 2, 2022

Finished rebasing the PR! 🎉
This still isn't working right with mark mode, so I'll have to polish this quite a bit.
If you are interested in reviewing this, you're welcome to do so, but I suggest waiting until I take this out of draft.

EDIT: things to do...

  • Bug: markMode doesn't switch the markers appropriately
  • Bug: marker is still displayed when you scroll down and it's outside of the viewport
  • Task: replace markers with y-beam provided by Kayla
  • Question: selection endpoints are currently inclusive. It's out of scope to make "end" exclusive and "start" inclusive. But should I try to fake it in this PR? It would be pretty important for when we're in mark mode and just moving the cursor around. 🤔 EDIT: NO

@carlos-zamora carlos-zamora force-pushed the dev/cazamor/ks/copy-mode branch from 25d14ae to 85dafbb Compare June 2, 2022 17:49
@carlos-zamora carlos-zamora force-pushed the dev/cazamor/ks/copy-mode branch from 85dafbb to 214d3af Compare June 3, 2022 00:11
@@ -318,10 +343,9 @@ Terminal::UpdateSelectionParams Terminal::ConvertKeyEventToUpdateSelectionParams
void Terminal::UpdateSelection(SelectionDirection direction, SelectionExpansion mode, ControlKeyStates mods)
Copy link
Member Author

Choose a reason for hiding this comment

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

Changes to this function may seem a little odd and unrelated, but they're necessary. Now that we're displaying the relevant y-beam end based on which endpoint we're moving, we need to make sure we're moving the correct one. Before, we could cheat it a bit since we didn't really have a concept of "start" and "end" (more just point 1 and 2).

Copy link
Member

Choose a reason for hiding this comment

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

oh this is much easier to read

@carlos-zamora
Copy link
Member Author

carlos-zamora commented Jun 7, 2022

Selection markers demo

A few things I want to highlight (heh)...

  • the selection markers match the color of the selection background
  • (not shown) the selection markers change in size when the font size changes
  • both markers are shown when a single cell selection is present
  • one marker is shown when moving one side and the appropriate one is shown when the selection pivots

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

this sparks joy

@@ -1052,7 +1047,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (_terminal->IsSelectionActive())
{
_terminal->SetBlockSelection(!_terminal->IsBlockSelection());
Copy link
Member

Choose a reason for hiding this comment

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

idle thought: maybe we file a follow up to change the shape of the markers when we're in block selection mode? idk.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah. Dustin and I were chatting about that the other day. it would be cool if we used some kind of 'L' shape for that.

Definitely a follow-up and something to mention/show in the spec.

@zadjii-msft zadjii-msft added the Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) label Jun 10, 2022
@DHowett

This comment was marked as resolved.

@carlos-zamora

This comment was marked as outdated.

src/cascadia/TerminalControl/ControlCore.cpp Outdated Show resolved Hide resolved
@@ -1012,7 +1038,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
auto lock = _terminal->LockForWriting();
_terminal->SelectAll();
_renderer->TriggerSelection();
_updateSelection(false);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too sure I like this actually! I can't divine rhyme or reason as to why we would clear sometimes and not others. Is there a guiding principle you're using?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, the general intent is...

  • are you using your keyboard? --> show markers
  • using a mouse? --> clear markers
  • search? --> clear
  • toggle block selection? --> probably don't mess with it? (I'm adding this in the next commit)

src/cascadia/TerminalControl/TermControl.cpp Show resolved Hide resolved
src/cascadia/TerminalCore/TerminalSelection.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalCore/TerminalSelection.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalControl/ControlCore.h Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 10, 2022
@DHowett

This comment was marked as outdated.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 10, 2022
@DHowett

This comment was marked as resolved.

@DHowett
Copy link
Member

DHowett commented Jun 13, 2022

Additional notes from bug bash

  • Looks like some things like Search and command palette trigger the flags to show up
  • DPI is still an issue
  • Make sure we aren't spending too much time scaling them on zoom (just in case it is slow)

@carlos-zamora
Copy link
Member Author

  • Make sure we aren't spending too much time scaling them on zoom (just in case it is slow)

Did a perf trace in VS. It doesn't even appear in the call tree. Relevant changes are here. Looks like the scale transform is cheap.

NOTE: later iteration adds dpi scaling, which is hardly different tbh. That's the one I profiled.

@carlos-zamora

This comment was marked as resolved.

@carlos-zamora
Copy link
Member Author

markers flip when at side boundaries

@carlos-zamora
Copy link
Member Author

@DHowett this is ready for review now :)

@carlos-zamora

This comment was marked as resolved.

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jun 20, 2022
@ghost
Copy link

ghost commented Jun 20, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@DHowett DHowett merged commit 6436e71 into main Jun 20, 2022
@DHowett DHowett deleted the dev/cazamor/ks/copy-mode branch June 20, 2022 22:47
@ghost
Copy link

ghost commented Jul 6, 2022

🎉Windows Terminal Preview v1.15.186 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants