helix icon indicating copy to clipboard operation
helix copied to clipboard

Improve clipboard yanking messages

Open 01mf02 opened this issue 3 years ago • 16 comments

Summary

When selecting some text with the mouse, the message "yanked main selection to system clipboard" appears at the bottom, yet the clipboard does not seem to contain the selected text.

Reproduction Steps

I tried this:

  1. hx
  2. Type "Hello".
  3. Select "Hello" with the mouse.
  4. Open a GTK application such as Mousepad or Firefox, and paste with middle mouse button or CTRL-V (tried both).

I expected this to happen:

The text "Hello" should appear in the GTK application.

Instead, this happened:

Some previously selected text appears in the GTK application.

Helix log

Nothing interesting here.

Platform

Linux

Terminal Emulator

xfce4-terminal 0.8.10

Helix Version

22.05-10-g370a16d0

01mf02 avatar May 30 '22 18:05 01mf02

Does this only happen when using the mouse? Does Spacey work to copy a selection to the system clipboard?

the-mikedavis avatar May 30 '22 18:05 the-mikedavis

This happens both with mouse and Space y.

I found the culprit in the meanwhile: In helix-view/src/clipboard.rs, Helix checks for the existence of several tools, such as xsel and xclip to use for clipboard operations. If none of these tools is available, then a NopProvider is used which provides a Helix-specific clipboard, but this can be hardly called a "system clipboard". Therefore, I find the message "yanked main selection to system clipboard" misleading. After installing xclip, yanking works as expected.

I see several ways to improve the current situation:

  • The error message in helix-term/src/commands.rs could be triggered when no clipboard tool is found. One way to achieve this would be to make the NopProvider always fail instead of always succeed.
  • The message "yanked main selection to system clipboard" could be changed to something like "yanked main selection to Helix clipboard (install a clipboard tool to use system clipboard)" when no clipboard tool is found.

01mf02 avatar May 31 '22 09:05 01mf02

Yeah improving that error message would be great. I think I would prefer that the system clipboard commands fail when the contents can't be copied so it's more noticeable. What do others think?

the-mikedavis avatar May 31 '22 14:05 the-mikedavis

Agreed!

archseer avatar Jun 01 '22 03:06 archseer

Interestingly, selecting with the mouse doesn't work on Windows while Space + y works just fine.

CptPotato avatar Jun 07 '22 12:06 CptPotato

Selecting with the mouse copies text to the secondary clipboard in Linux, which doesn't exist in Windows. We could copy to the clipboard for windows in this case, but that would probably be too disruptive - the secondary clipboard in Linux doesn't override the contents of a normal ctrl+c made in some other application, while in Windows (due to a lack of multiple clipboards) it will.

sudormrfbin avatar Jun 07 '22 12:06 sudormrfbin

The distinction between mouse select and y isn't very clear:

  • Mouse: yanked main selection to system clipboard
  • Space + y: joined and yanked 1 selection(s) to system clipboard

It is not clear from this prompt that one of them goes to the middle click clipboard yet the other one goes to the normal (Ctrl+C/V) clipboard. Does anyone know what's the correct term for not only X (which I know are clipboard and primary) but also Wayland? (Maybe we just call them "system clipboard" and "system selection clipboard"? Also, the joined and yanked 1 selections(s) is unnecessary. Simply yanked selection to system clipboard would do.

DuckDuckWhale avatar Jun 27 '22 05:06 DuckDuckWhale

Copying to system clipboard via space+y does not work on Windows through WSL.

jquesada2016 avatar Jul 30 '22 14:07 jquesada2016

https://github.com/helix-editor/helix/issues/2132

the-mikedavis avatar Jul 30 '22 14:07 the-mikedavis

@the-mikedavis thank you VERY much for the referral!

jquesada2016 avatar Jul 30 '22 15:07 jquesada2016

cross-posting here:

I've started working on this, learning Rust as I go 😅 Adding this to the healthcheck now, then I'll look into the error message in-app: #3271

amitbeka avatar Jul 31 '22 07:07 amitbeka

I'm using helix 22.08.1 (66276ce6) on mac + iterm2, when I select text with mouse it says yanked main selection to system clipboard but the actual text is not in the clipboard/any register. Using space + Y prints the same message but actually works as expected.

shaded-enmity avatar Sep 19 '22 13:09 shaded-enmity

Running on RHEL 8 here, and space + y yanks to system clipboard, but the mouse select does not. hx --health shows using xclip.

I've just looked at other issues, and now realize that the mouse selection clipboard is the middle-mouse click clipboard, while space + y is the ctrl+c/v clipboard. Also, I now see someone else said the same thing further up facepalm

ngraham20 avatar Oct 14 '22 16:10 ngraham20

Hi i am trying to use space + Y to be able to copy text from helix to main clipboard but it doesn't, try to paste the text outside helix but it doesn't work. I have xclip installed on a Chrome OS with debian 11 VM

$ hx --health

Config file: default Language file: default Log file: /home/myuser/.cache/helix/helix.log Runtime directory: /home/myuser/.config/helix/runtime Clipboard provider: xclip System clipboard provider: xclip

me-tantaroth avatar Oct 23 '22 19:10 me-tantaroth

Faced the same problem. I had no idea why copy paste to system clipboard wasn't working, when it clearly showed a success message. I thought it was just a helix bug. Technically it is tho. Thanks to @01mf02 for providing a workaround with xclip. (I'm running ubuntu)

sayandcode avatar Nov 11 '22 10:11 sayandcode

Okay, this is something I've encountered as well, and it works after install xclip. I've also tried this with wl-clipboard, and it works fine.

Ashvith10 avatar Mar 16 '23 20:03 Ashvith10

When I select the entire document with % and then try to yank to system clipboard, helix freezes. When I select a line with x and then try to yank to system clipboard, nothing gets yanked.

nexovec avatar Oct 08 '23 11:10 nexovec

@nexovec Install xclip if you're on x11, or wl-clipboard if you're on wayland.

b0okle avatar Oct 30 '23 12:10 b0okle