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 an experimental setting for moving the cursor with the mouse #15758

Merged
merged 10 commits into from Aug 14, 2023

Conversation

zadjii-msft
Copy link
Member

Summary of the Pull Request

This adds a new experimental per-setting to the terminal.

"experimental.moveCursorWithMouse": bool

When:

  • the setting is on
  • AND you turn on shell integration (at least 133;B)
  • AND you click is somewhere after the "active command" mark

we'll send a number of simulated keystrokes to the terminal based off the number of cells between the place clicked and where the current mouse cursor is.

PR Checklist

Detailed Description of the Pull Request / Additional comments

There was a LOT of discussion in #8573. This is kinda a best effort feature - it won't always work, but it should improve the experience most of the time. We all kinda agreed that as much as the shell probably should be responsible for doing this, there's myriad reasons that won't work in practicality:

  • That would also disable selection made by the terminal. That's a hard sell.
  • We'd need to invent some new mouse mode to support click-to-reposition-but-drags-to-select-I-don't-want
  • We'd then need shells to adopt that functionality.

And eventually settled that this was the least horrifying comprimise.

This has e d g e c a s e s:

  • Does it work for wrapped lines? Well, kinda okay actually.
  • Does it work for vim/emacs? Nope.
  • Does it work for emoji/wide glyphs? I wouldn't expect it to! I mean, emoji input is messed up anyways, right?
  • Other characters like ESC (which are rendered by the shell as two cells "^[")? Nope.
  • Does it do selections? Nope.
  • Clicking across lines with continuation prompts? Nope.
  • Tabs? Nope.
  • Wraps within tmux/screen? Nope.

https://github.com/xtermjs/xterm.js/blob/master/src/browser/input/MoveToCell.ts has probably a more complete implementation of how we'd want to generate the keypresses and such.

src/cascadia/TerminalControl/ControlCore.cpp Outdated Show resolved Hide resolved
Comment on lines +1788 to +1789
_terminal->SendKeyEvent(key, 0, {}, true);
_terminal->SendKeyEvent(key, 0, {}, false);
Copy link
Member

@lhecker lhecker Jul 26, 2023

Choose a reason for hiding this comment

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

For purposes like this it would be nice if we could stop flushing our input pipe so that the keystrokes are sent as a unison. For both pwsh and cmd this would avoid re-printing the entire commandline on every cursor navigation. One option would be to do something like _terminal->CorkInputPipe() and UncorkInputPipe() (borrowing TCP_CORK terminology), but I also somewhat feel like it would be better if we instead made it so that SendKeyEvent will never flush the input pipe and instead we add a _terminal->FlushInput() function which you need to call when you're done generating input. Alternatively, we could also extract TerminalInput out of Terminals control and accumulate a std::string here before sending it off. Or we just generate cursor sequences ourselves. I don't think there's any fantastic solution, but there's a lot of alright ones. 🙂

(xterm.js does this as well btw.)

Copy link
Member

Choose a reason for hiding this comment

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

Could we create a follow-up issue for this? I think it would be worthwhile in general to keep track of features that would benefit of corking/uncorking the input pipe.

@zadjii-msft
Copy link
Member Author

TODO!

  • Use CMD.
  • Submit a command.
  • Then click off to the right of the prompt.
  • We'll send → until that point, which CMD will use to fill in the rest of the previous commandline.

gotta find a way to clamp it to the rightmost character. Probably wont work right for folks with right-aligned prompts.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@DHowett
Copy link
Member

DHowett commented Aug 10, 2023

nit: maybe repositionCursorOnClick is more in line with what other terminals call it?

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Sorry to block two in a row, but I've got Questions! And a suggestion for a name.

false,
needToCopy);

VERIFY_IS_TRUE(core->HasSelection());
Copy link
Member

Choose a reason for hiding this comment

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

wait, why now does a single left click result in a selection? I thought it for sure didn't do that...

Copy link
Member Author

Choose a reason for hiding this comment

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

that true means shift was pressed. A single click with a shift does select

VERIFY_ARE_EQUAL(expectedStart, start);
VERIFY_ARE_EQUAL(expectedEnd, end);
}
VERIFY_IS_TRUE(gotSelectionUpdate);
Copy link
Member

Choose a reason for hiding this comment

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

I don't actually understand how this selection test is related to click-to-reposition...

Copy link
Member Author

Choose a reason for hiding this comment

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

It's actually not! But I broke that selection rendering thing in that last bug bash, in an earlier commit in this PR. This test I wrote to make sure I un-broke it, and won't re-break it in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. I thought it was a render lock bug, so i didn't put the two together

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Aug 10, 2023
@zadjii-msft
Copy link
Member Author

repositionCursorOnClick

Sure, I don't care

@github-actions

This comment has been minimized.

@zadjii-msft zadjii-msft assigned lhecker and unassigned DHowett Aug 11, 2023
@zadjii-msft zadjii-msft enabled auto-merge (squash) August 14, 2023 10:45
@zadjii-msft
Copy link
Member Author

(force merging since it seems like GH is confused. Probably since we changed the build rules during the course of this PR)

@zadjii-msft zadjii-msft merged commit b556594 into main Aug 14, 2023
17 checks passed
@zadjii-msft zadjii-msft deleted the dev/migrie/f/8573-experiment branch August 14, 2023 12:37
zadjii-msft added a commit to MicrosoftDocs/terminal that referenced this pull request Sep 28, 2023
I could list the PRs but I aint got time for that

closes #687
closes #668
Docs microsoft/terminal#15758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants