zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
20.57k stars 637 forks source link

Use both primary and system clipboards #2394

Open amokfa opened 1 year ago

amokfa commented 1 year ago

Clipboard behavior in zellij is completely different from the rest of linux applications:

  1. Selecting text using mouse This is supposed to copy text to the primary selection, which can then be pasted using middle mouse button. If I select some text in zellij using my mouse, I'm unable to paste it to either zellij, or other text fields using middle mouse. By comparison, I can select text using mouse and paste it to transfer it between chrome and any terminal emulator.

  2. Pasting text using middle mouse I can select some text using mouse and paste it into both chrome and terminal emulators using middle mouse, but pressing the middle mouse in zellij does nothing.

I can disable copy on select, and set a copy keybinding to get half of the desired behavior. But I see no way of using both primary selection even with this setup.

amokfa commented 1 year ago
  1. In every other terminal I can select a word using double click, and a line with a triple click. In zellij, they don't do anything.
amokfa commented 1 year ago

@imsnif @jaeheonji I can work on this issue. Here's what I have in mind:

  1. We remove copy_on_select and copy_clipboard options.
  2. Whenever the user makes a selection using the mouse, we copy the selection content to the primary selection.
  3. With content selected, pressing the copy keybinding will copy the contents to the system clipboard.
  4. Middle click will paste the contents of primary selection.
  5. Optionally we could remove the copy_command option as well and copy to the correct system clipboard based on environment. Need to test if it will work in wayland/xwayland setups.

This will make zellij behave like every other linux application I'm aware of as far as clipboard is concerned. Let me know how that sounds.

tlinford commented 1 year ago

Hey @amokfa, I like your proposal, and agree with most things. Also, thanks for volunteering to pick this up, I can try and help you out with this :)

Just for a bit of background, the current default behavior (copy_on_select on) was implemented purposefully to match what tmux does by default I guess (https://github.com/zellij-org/zellij/pull/448#issuecomment-863369007).

That said here is my take on your plan:

  1. keep the copy_on_select option, when it is enabled keep current behavior (maybe we could copy selection to both primary and system). when off, adopt the new more "standard" approach.
  2. depends on copy_on_select option
  3. same
  4. This is where things get tricky. Unfortunately as a terminal application, there isn't a great way to interact with the system clipboard. A couple of possibilities are:

    • use osc52, but support for reading from the clipboard is limited to only Alacritty AFAIK, because it's considered unsecure.
    • on middle click, paste the contents of the current zellij selection. This is ok, but misses the case of wanting to paste from outside of zellij
    • something similar to copy_command to allow the user to configure the right thing
      1. This can also be problematic, considering that zellij needs to be able to run on servers with no x/wayland, and also mac and win (someday). More context on this in the original mouse support pr: https://github.com/zellij-org/zellij/pull/448#issuecomment-849819514. But it might be worth figuring out if this is doable in a way that matches these requirements. The way helix handles this seems very smart and might be useful as a reference: https://github.com/helix-editor/helix/blob/8a3ec443f176218384db8c8610bbada9c43a6ea5/helix-view/src/clipboard.rs

    Let me know what you think.

    cc @imsnif please feel tree to add anything/correct me if I got something wrong here :)

imsnif commented 1 year ago

I have not gone into the weeds of this proposal, as I trust @tlinford 's judgement - the only thing I want to stress is that removing existing configuration parameters is a breaking change and that we should really try to avoid it. And also: I'm happy to change the bahavior of Zellij here if you think it's good, but there will always be users who will not like the new behavior and want things to be as they were before. For them we should provide an escape hatch, likely in the form of a new configuration attribute that will allow them to restore the previous behavior.

ahberg commented 1 year ago

1 It is possible to use mouse copy/paste if you hold on shift . (it disable mouse mode and isn't optimal ). 2 Bindings "Alt c" should be enabled when copy_on_select=false. https://github.com/zellij-org/zellij/blob/dfae62526b7bf785feac615ec93da0857cba2dd8/example/default.kdl#L4-L5

grm34 commented 1 year ago

I use this workaround to get paste working on CTRL+SHIFT+V

copy_command "wl-copy -p"
popey commented 6 months ago

Zellij is lovely (I only just discovered it myself)! Would someone be willing to revisit this issue? It's a shame that on Linux we have inconsistent copy/paste behaviour between the primary terminal and other applications.

wiraki commented 3 months ago

Hello, I also just arrived here because I noticed that double-clicking on text in the scroll buffer did not select it. I had not realized but I am quite used to it being the case that this is now bothering me.

Is there any hope this issue is re-visited? :)

dimyself commented 2 months ago

1 It is possible to use mouse copy/paste if you hold on shift . (it disable mouse mode and isn't optimal ). 2 Bindings "Alt c" should be enabled when copy_on_select=false.

https://github.com/zellij-org/zellij/blob/dfae62526b7bf785feac615ec93da0857cba2dd8/example/default.kdl#L4-L5

I'm new to Zellij

I'm using dropdown xfce-terminal

I can get copy text working by holding +, then to paste

But I would like a way to remove and just copy using double / triple mouse click for copy and middle mouse click for paste.

I assume that is what this open issue is about if I'm reading it right?

Or, is there a setting / option / config I can change to remove the key as necessary for copying?

Thank you!!!