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

Introduce option to right click to copy #4404

Open
mitchellh opened this issue Jan 2, 2025 · 11 comments
Open

Introduce option to right click to copy #4404

mitchellh opened this issue Jan 2, 2025 · 11 comments
Labels
gui GUI or app issue regardless of platform (i.e. Swift, GTK)

Comments

@mitchellh
Copy link
Contributor

Discussed in #4381

Originally posted by 7ijme January 2, 2025
When I right-click, I don't want a context menu to open. I want it to copy the current selection.

This is what it looks like now:
image

Solution

We should introduce a new configuration option copy-on-right-click (similar to copy-on-selection), boolean default to "false" that can be set to true by those who wish for this behavior.

When true, context menus are disabled and text is copied. When mouse reporting is enabled, this should also copy so long as there is an active selection.

We should make this work on both macOS and Linux. This is more prevalent in the Linux world but I see no reason to disallow it on macOS since it's opt-in.

@mitchellh mitchellh added the gui GUI or app issue regardless of platform (i.e. Swift, GTK) label Jan 2, 2025
@LovecraftianGodsKiller
Copy link

I second this.

I'd also like an option for middle-click to paste; unless it already exists.

@peterhowe-adwanted
Copy link

peterhowe-adwanted commented Jan 6, 2025

I use the middle mouse button (via Logitech Options+) for Mac's Mission Control, so it would be great to be able to have paste on right click as I already use copy-on-select = true.

@jzetterman
Copy link

I don't mean to hijack, but would it make sense to do right click to paste while you're doing this work as well? See 3783.

@han5
Copy link

han5 commented Feb 6, 2025

In other terminals, you right click on a URL and it gives the option to Open Link.
At least quick select / copy will work as well.

@chenzhiwei
Copy link

There is already a copy-on-selection, I think a paste-on-right-click is more useful.

In Windows Terminal, the mouse behavior have more optoins:

Left-click and drag your mouse to create a selection. Double-click expands the selection by word, whereas triple-click expands by line.

If you are holding the Alt key, you will create a block selection (as opposed to a line selection). Block selections create a rectangular region that do not wrap to the end of the line.

If you are holding the Shift key, you can explicitly expand the selection to a specific point on the terminal without the need to click and drag.

Once you have a selection present, you have a few options. A single left-click will clear your selection. If you actually want to use it, you can right-click to copy the selected text to your clipboard and clear the selection. If you right-click again, the contents of your clipboard will then be pasted into the terminal.

https://learn.microsoft.com/en-us/windows/terminal/selection#mouse-support

@IamTheLime
Copy link

I believe the intended feature is something along these lines Right Click to Copy MR

@jcollie
Copy link
Collaborator

jcollie commented Feb 23, 2025

Before we start merging pull requests, we should really spend some more time thinking about the best config for this.
Having a dedicated copy-on-right-click config seems way too specialized. Things will quickly get out of hand as we want to do other things with mouse button actions. In particular, pasting (instead of copying) with right click seems like a viable option as well. If we don't develop full-blown mouse button remapping as discussed in #3848 we should at least make the right click config a little more extensible.

I'd recommend something like this:

right-click-action = open-context-menu
right-click-action = copy
right-click-action = paste

open-context-menu would be the default.

@mitchellh
Copy link
Contributor Author

Things will quickly get out of hand as we want to do other things with mouse button actions.

The goal with this was to solve a short term problem. Long term, we need a generic mousebind (akin to keybind) config to specify mouse behaviors in general and move away from our hardcoded approach. There are various issues requesting this and something I'm committed to, it's just that mouse bindings tend to be less important than keybindings so they took a lower priority.

I'd be fine considering right-click-action for now as well, but I'd be afraid that'd lead to a lot more complexity as people try to add more right click actions, suggest introducing left-click-action, etc. When what we really need are arbitrary mouse bindings. copy-on-right-click seems analogous to copy-on-select (also a mouse binding, a left-up-action when a selection is active).

I suppose my main argument is I'm not sure its worth added complexity for now, this is just a particularly common request.

For your right-click-action = paste request, is that requested somewhere?

@jcollie
Copy link
Collaborator

jcollie commented Feb 23, 2025

For your right-click-action = paste request, is that requested somewhere?

#4404 (comment)
#4404 (comment)

@00-kat
Copy link
Contributor

00-kat commented Feb 23, 2025

For your right-click-action = paste request, is that requested somewhere?

There's also #3438 and #3783 and #5145. The second is from the same author as the first comment jcollie linked, so deduplicating would mean four separate instances.

Multiple people in those discussions I linked seem to want both copy and paste on right click (copies if there is a selection, pastes otherwise), perhaps that should be accommodated by right-click-action too?

@jcollie
Copy link
Collaborator

jcollie commented Feb 23, 2025

Here's a potential syntax for a general mouse button action config. The performable prefix is mainly meant for use with the open-url or copy-url actions which would make that action a no-op if there's no URL underneath the click (or similarly no selection). A subsequent action could then open a context menu.

mouse-button-action = (performable:)?(left|right|middle|button-\d+)\+(press|release)(\+(single|double|triple|[1-9][0-9]*))?=(open-menu|open-url|copy-url|copy|select-and-copy|paste|select-word|select-line|unbind)

The difference between copy and select-and-copy is that select-and-copy will select a word if the click is not on an existing selection.

If we're not ready to implement that, right-click-action would be forward-compatible:

right-click-action = select-and-copy ==> mouse-button-action = right+press+single=select-and-copy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gui GUI or app issue regardless of platform (i.e. Swift, GTK)
Projects
None yet
Development

No branches or pull requests

9 participants