-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Terminal: Support keyboard text selection & navigation #715
Comments
@carlos-zamora this may be of interest |
Also, if the tmux property mouse-mode does not work in the new Terminal. |
One possible implementation would be just to do what cmd does, where if the user has selected text and presses "Enter", it will just copy the selected text to the clipboard. |
Or maybe it would be possible to let the application running control what's happening when marking... |
If keyboard text selection is added, please don't forget about things like Shift+Home and Shift+End. You could also have a selection go up and down a line/row with Shift+Up and Shift+Down. Oh and with all these ligatures, copying and pasting text should probably uncombine those ligature characters - so the font choice does not affect what may get pasted in another place. |
Added the "Help-Wanted" label. Most of this work should be able to go in
|
Terminal is slowly driving me crazy because unlike ConEmu pressing clears the selection without copying it to the clipboard, having full-on keyboard only text selection would be a massive addition. |
One fun wrinkle--PSReadLine handles buffer selection and navigation for Windows PowerShell and PSCore. So if this does get implemented, there should also be an option to disable it per-profile, so a shell can handle selection itself. |
@pingzing I'm also using PSReadLine, but I'm unaware of the feature. Can you give me a hint? (can't find any documentation on this). What I'm talking about in this issue is the following (beware awesome screencapturing): |
I think it only works for the input buffer, and not previously-written text. No idea if it's documented, but it's definitely in the keybindings. For example, invoking
My fear is that if Terminal implements this, it'll interfere with PSReadLine's own handling. ConEmu has similar behavior, which I have to disable if I want PSReadLine's behavior. |
Implements the following keyboard selection non-configurable key bindings: - shift+arrow --> move endpoint by character - ctrl+shift+left/right --> move endpoint by word - shift+home/end --> move to beginning/end of line - ctrl+shift+home/end --> move to beginning/end of buffer This was purposefully done in the ControlCore layer to make keyboard selection an innate part of how the terminal functions (aka a shared component across terminal consumers). ## References #715 - Keyboard Selection #2840 - Spec ## Detailed Description of the Pull Request / Additional comment The most relevant section is `TerminalSelection.cpp`, where we define how each movement operates. It's basically a giant embedded switch-case statement. We leverage a lot of the work done in a11y to perform the movements. ## Validation Steps Performed - General cases: - test all of the key bindings added - Corner cases: - `char`: wide glyph support - `word`: move towards, away, and across the selection pivot - automatically scroll viewport - ESC (and other key combos) are still clearing the selection properly
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Has this been implemented/released in a preview build? |
## Summary of the Pull Request Introduces a non-configurable version of mark mode to Windows Terminal. It has the following interactions defined: - <kbd>ctrl+shift+m</kbd> --> Enter Mark Mode - when in Mark Mode... - <kbd>ESC</kbd> --> Exit Mark Mode - arrow keys --> move "start" - <kbd>shift</kbd> + arrow keys --> anchor "start", move "end" - <kbd>ctrl+a</kbd> --> select all - when a selection is active... When in mark mode, the cursor does not blink. ## References #4993 - [Epic] Keyboard Selection ## PR Checklist * [X] Closes #715 * [X] Provides a resolution for #11985 ## Detailed Description of the Pull Request / Additional comments - `TermControl`: - `TermControl.cpp` just adds logic to prevent the cursor from blinking when in mark mode - `ControlCore` - in the same place we handle quick edit, we add an entry point to mark mode - `TerminalCore` - this leverages `UpdateSelection()` and other quick edit functions to make mark mode happen ## Validation Steps Performed - [x] Make selection, split pane, close pane - NOTE: A similar scenario caused a crash at one point. Really weird. Keep an eye on it. - [x] Cursor is off when in mark mode - [x] general movement/selection - [x] general movement/selection that forces the viewport to move - [x] In mark mode, selectAll... - [x] arrow keys --> move start - [x] shift + arrow keys --> move end - [x] (regardless of mark mode) if selection active, enter --> copy to clipboard
## 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
🎉This issue was addressed in #13053, which has now been successfully released as Handy links: |
## Summary of the Pull Request This is a spec specifically dedicated to Mark Mode. It's an addition to the Keyboard Selection spec. I felt that it makes the most sense to make this a separate PR because there's a lot of ideas that are very specific to Mark Mode, and this gives us the space to modify some of that behavior and get a good look at how other terminal emulators designed this feature. ## References #2840 - Keyboard Selection Spec (base spec/branch/PR) ## PR Checklist * [X] Contributes to #715
If/when this is implemented I hope it will be an option! I've build in my own functionality in my application (CTRL+C, CTRL+V, CTRL+X, text-selection with SHIFT+ARROWS, SHIFT+HOME, SHIFT+END etc). I would be unhappy if my hard work gets corrupted by an native implementation....so please make it possible to disable it in settings. It's a real pain in the Windows legacy console (in advance mode).....the text-selection is forced so pushing e.g. SHIT+HOME is captured by the console and are not parsed on to the application, please don't make same mistake. |
@MrM40 This was implemented like, 4 months ago, and has been shipped in Preview 1.15 for some time now. Feel free to check out that release and file new issues if you find any |
PowerShell has its own text selection it maintains, as a part of the shell itself. You'll note that PowerShell's text selection works the same in 1.15 as it did in previous versions, even the same as it did in the vintage console. The text selection added in the Terminal needs to be started first, either with a keyboard selection, or the |
OK, I see. Expected it to work the same was as in legacy console in advance mode, where it just work natively (but make it impossible to make you own implementation, as e.g. SHIFT-LEFT never get parsed to your application). |
@carlos-zamora Two years after this feature was implemented, I want to say that it's an absolute joy. This was the one thing that prevented me from using Microsoft Terminal, and now I use it so often. Thank you so much for implementing it. |
is this already supported? i cant use it |
Hello,
I'm using tmux on Linux machines and ConEmu on Windows machines and I really love that I can do text selection with the keyboard.
In ConEmu, there is a keybinding for "Start text selection (like text editors)", whereas in tmux there is the same thing with
<prefix><b>
(I think that is default), where I get a cursor that I can move with the arrow keys around the console window.While doing this, I can select text while holding shift and (in case of ConEmu) press ENTER to copy the text into the clipboard and end the text selection.
It can also be compared with Vim's visual mode.
It would be nice if the new Windows Terminal could support this out of the box, so I can use it in e.g. PowerShell :-)
The text was updated successfully, but these errors were encountered: