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

Make middle-click do copy-and-paste in integrated terminal #187365

Closed
lhmouse opened this issue Jul 8, 2023 · 15 comments · Fixed by #136633
Closed

Make middle-click do copy-and-paste in integrated terminal #187365

lhmouse opened this issue Jul 8, 2023 · 15 comments · Fixed by #136633
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes terminal General terminal issues that don't fall under another label verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@lhmouse
Copy link

lhmouse commented Jul 8, 2023

Maybe this is a dup of #26902.

The traditional mouse button for copy-and-then-paste on Linux is the middle button, while it is the right button on Windows. However, the notable MSYS2 terminal emulator, mintty, which is also utilized by the Git Bash, defaults to the linux configuration (but it's configurable). As a dual-platform user, having to be aware of this divergence is really a pain. Thus, I suggest we make this configurable, as I am more accustomed to the middle button.

@meganrogge meganrogge added feature-request Request for new features or functionality terminal General terminal issues that don't fall under another label labels Jul 10, 2023
@vscodenpa vscodenpa added this to the Backlog Candidates milestone Jul 10, 2023
@vscodenpa
Copy link

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@vscodenpa
Copy link

🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@vscodenpa vscodenpa modified the milestones: Backlog Candidates, Backlog Jul 12, 2023
@Tyriar
Copy link
Member

Tyriar commented Jul 13, 2023

Info for implementor: This would mostly be a Windows feature that would sort of emulate the Linux OS-level selection clipboard feature. We might want to wait on #3130

@lhmouse
Copy link
Author

lhmouse commented Jul 13, 2023

That doesn't have to have anything to do with the clipboard. By default 'copy on selection' is enabled on Linux, and with that turned on, a middle click is nothing but a paste command.

I think I will need to make some more experiments, especially with 'copy on selection' turned off.

@lhmouse
Copy link
Author

lhmouse commented Jul 18, 2023

Tested on MATE terminal, Linux Mint 21.2 'Victoria' x86_64:

  1. Uncheck Edit -> Profile Preferences -> Copy selected text into clipboard.
  2. Select random text "text one" with the mouse, then press Ctrl-Insert to copy it. Selected text is now copied into clipboard.
  3. Select another block of text "text two" with the mouse.
  4. Press Shift-Insert. "text one" is inserted, so pressing Shift-Insert pastes the clipboard.
  5. Press the mouse middle button. "text two" is inserted, so pressing middle button pasts the selection.
  6. Press Shift-Insert again. "text one" is still inserted, so pressing middle button just duplicates the selection, having no effect on the clipboard.

@Tyriar
Copy link
Member

Tyriar commented Jul 18, 2023

@lhmouse I misspoke, I mean the OS' "primary selection" which is often accessible via clipboard APIs.

@Tyriar
Copy link
Member

Tyriar commented Jul 18, 2023

And for Windows, primary selection does not exist, so we would either want to emulate it (which sucks because it is not cross-app), or just hook up the regular clipboard.

@lhmouse
Copy link
Author

lhmouse commented Jul 18, 2023

And for Windows, primary selection does not exist, so we would either want to emulate it (which sucks because it is not cross-app), or just hook up the regular clipboard.

This is acceptable. The MSYS2 mintty, by configuration, assigns middle button the Paste command. So a middle click pastes the system clipboard; it's no difference from Ctrl-Shift-V or Shift-Insert.

@ian-h-chamberlain
Copy link

As a macOS user, I would also love to have middle-click paste similar to Linux functionality, but probably just pasting directly from clipboard similar to the aforementioned Windows implementation.

See also this stackoverflow asking about it: https://stackoverflow.com/questions/69882273/how-to-enable-middle-mouse-button-click-to-paste-selected-text-in-vscodes-termi/72308315#72308315

They in turn pointed to some code which seems to hardcode for isLinux, in case that's useful:

if (event.which === 2 && isLinux) {

@lhmouse
Copy link
Author

lhmouse commented Nov 5, 2023

I think I have to disable this on Linux (and consequently, on Windows too) for now, as the touchpad is very easily mishandled, causing vscode to paste text not only in the terminal, but in the editor area too.

@glaserf
Copy link

glaserf commented Mar 1, 2024

Any update on this? I work with vscode and "native" Linux shells side-by-side on a Windows workstation. This different behavior on what's essentially two windows for me is driving me crazy.

@lhmouse
Copy link
Author

lhmouse commented Mar 2, 2024

Any update on this? I work with vscode and "native" Linux shells side-by-side on a Windows workstation. This different behavior on what's essentially two windows for me is driving me crazy.

Me, too. And the solution is to disable auto copy-on-select, and always copy explicitly with Ctrl-Insert and paste with Shift-Insert. It's cumbersome, but at least is consistent.

@stevekm
Copy link

stevekm commented Mar 28, 2024

I am kinda confused by this GitHub Issue, I thought that "middle-click to Paste" was already an available feature as per

https://stackoverflow.com/questions/36723333/how-to-enable-middle-mouse-button-click-paste-in-vs-code

#14610

Please set "editor.selectionClipboard": false in your user settings. This will make it so we don't paste from the selection clipboard when you press the middle button and we don't write to the selection clipboard when a selection is made in the editor.

However, searching for editor.selectionClipboard in the VS Code settings on version code-server: v4.14.1 / Code: 1.79.2 does not yield any results.

Also kinda confused because it seems like the desired behavior would be "copy on select" followed by "paste on middle-click".

also kinda confused by this

The traditional mouse button for copy-and-then-paste on Linux

been using Linux daily for many many years, I have never heard of a "traditional mouse button behavior" in Linux. Aren't these behaviors controlled by the third-party software such as your terminal emulator and desktop environment? If you are seeing some default behavior in your Linux installation, I am not sure that its coming from Linux itself, but from the third-party packages you are running which are not standardized.

regardless of what is perceived as "traditional mouse button behavior" it seems like the "copy" and "paste" functionalities related to mouse behavior in the integrated terminal should be configured separately. So you can have "highlight on select" and "paste on middle-click", or whatever combination of actions, that you prefer

@lhmouse
Copy link
Author

lhmouse commented Mar 29, 2024

@stevekm On Linux there are two clipboards, one is provided by X which can be printed with xclip -o, and the other is provided by my desktop environment which is controlled by Ctrl-C, Ctrl-V, etc.

I am on Cinnamon so I take it as an example:

  1. After some text is selected (no whether it is in a terminal or not), the X clipboard is updated and the output of xclip -o changes, but the Cinnamon clipboard doesn't change.
  2. If I enable System Settings -> Mouse and Touchpad -> Paste the current selection when middle-click is pressed, pressing middle moused button pastes the X clipboard. This has almost the effect of combination of copy-on-select and then paste-on-middle-click, except that the Cinnamon clipboard (Ctrl-C, Shift-Insert) is unaffected.
  3. This explains why I am not willing to enable copy-on-select: It may unintentionally overwrite the clipboard just because something is selected. Copy-and-paste on click is less likely to be mishandled.

@stevekm
Copy link

stevekm commented Mar 29, 2024

Thanks @lhmouse

X is not a part of Linux. It is included in some desktop Linux distros but its not a core part of the Operating System. Linux desktop environments and desktop distro's are not standardized and are heavily influenced by whatever arbitrary combination of third-party packages their designers decide to include. It seems very strange and not quite appropriate to change the behavior of a cross-platform app like VS Code in response to a non-standard configuration of third party packages on a subset of distributions of an OS.

This is why I suggest that the correct implementation of this is to allow for de-coupled behaviors for both copying and pasting. So that if one or the other or both are causing you problems on your specific combination of non-standard third party desktop environment packages, you can more easily choose the exact combination of configurations to suit your needs.

Also I am refering to the "Copy On Select" setting in VS Code, not in your OS or desktop environment.

terminal.integrated.copyOnSelection

Screenshot 2024-03-29 at 9 36 13 AM

This is a VS Code Terminal setting. It does not cause text selected in e.g. the VS Code Editor to automatically copy.

This explains why I am not willing to enable copy-on-select: It may unintentionally overwrite the clipboard just because something is selected.

If you are using copy-on-select, and you dont want some text to be copied, then just dont select it. If you accidentally selected the wrong text for copying, then just re-select the correct text. If you are worried about losing your clipboard contents, then make sure to Paste it before you make another selection.

@Tyriar Tyriar modified the milestones: Backlog, April 2024 Apr 2, 2024
@vscodenpa vscodenpa added the unreleased Patch has not yet been released in VS Code Insiders label Apr 2, 2024
@vscodenpa vscodenpa added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Apr 4, 2024
@Tyriar Tyriar added the verification-needed Verification of issue is requested label Apr 22, 2024
@benibenj benibenj added the verified Verification succeeded label Apr 23, 2024
@Tyriar Tyriar added the on-release-notes Issue/pull request mentioned in release notes label Apr 25, 2024
@microsoft microsoft locked and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes terminal General terminal issues that don't fall under another label verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants