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

Unable to copy text after copying text to unnamedplus in neovim under wayland #6890

Closed
ch3n9w opened this issue Dec 7, 2023 · 8 comments
Closed
Labels

Comments

@ch3n9w
Copy link

ch3n9w commented Dec 7, 2023

Describe the bug
After copy text in neovim and quit, I can't copy text in kitty, unless I focus to another window and then focus back.

To Reproduce
Steps to reproduce the behavior:

  1. launch kitty, open file with nvim <file>
  2. copy text A to unnamedplus by pressing yy in neovim
  3. quit nvim, paste the text copied from neovim, the output should be text A as expected
  4. select and copy text B in kitty
  5. paste the copied text, the output is text A rather than text B
  6. focus to another window (like another kitty terminal), and focus back
  7. reproduce step 4 and 5, the output is text B as expected

Environment details

kitty 0.31.0 created by Kovid Goyal
Linux Shadow 6.6.4-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Mon, 04 Dec 2023 00:28:58 +0000 x86_64
Arch Linux 6.6.4-zen1-1-zen (/dev/tty)

DISTRIB_ID="Arch"
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="Arch Linux"
Running under: Wayland
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib/kitty
  extensions dir: /usr/lib/kitty/kitty
  system shell: /bin/zsh

Config options different from defaults:

Important environment variables seen by the kitty process:
        PATH                                /opt/google-cloud-cli/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin
        LANG                                en_US.UTF-8
        SHELL                               /bin/zsh
        GLFW_IM_MODULE                      ibus
        DISPLAY                             :1
        WAYLAND_DISPLAY                     wayland-1
        USER                                ch4ser
        XCURSOR_SIZE                        24
        XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session1
        XDG_BACKEND                         wayland
        XDG_SEAT                            seat0
        XDG_SESSION_DESKTOP                 Hyprland
        XDG_SESSION_TYPE                    wayland
        XDG_CURRENT_DESKTOP                 Hyprland
        XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
        XDG_SESSION_CLASS                   user
        XDG_VTNR                            1
        XDG_SESSION_ID                      2
        XDG_RUNTIME_DIR                     /run/user/1000
        XDG_DATA_DIRS                       /home/ch4ser/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share

This debug output has been copied to the clipboard
~

neovim version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1700008891

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Additional context

the issue can be reproduced with kitty --config NONE, and the neovim's configuration only contains set clipboard=unnamedplus in ~/.config/nvim/init.vim. The compositor is hyprland.

@kovidgoyal
Copy link
Owner

Update to neovim 0.10 which has native osc52 support and you should be fine. Or use https://github.com/ojroques/nvim-osc52

@ch3n9w
Copy link
Author

ch3n9w commented Dec 7, 2023

@kovidgoyal Actually, I think the issue has no related with osc52, since I can reproduce the issue with no configuration about ocs52, and of cause, the problem still exists when I use nvim-osc52 or use neovim nightly.

BTW, it seems the issue disappears when switching to other terminal emulators like gnome terminal or alacritty.

@kovidgoyal
Copy link
Owner

Then please come up with a reproducer without nvim involved.

@ch3n9w
Copy link
Author

ch3n9w commented Dec 8, 2023

@kovidgoyal You are right, the issue can be reproduced without neovim.

  1. open kitty with kitty --config NONE
  2. use mouse selection and ctrl-shift-cto copy text A in terminal
  3. paste with ctrl-shift-v, the output is text A
  4. execute echo hello | wl-copy
  5. paste with ctrl-shift-v, the output is hello
  6. repeat step 2 to copy text other than hello
  7. paste with ctrl-shift-v, the output is still hello
  8. focus to another window and focus back, and repeat step 6 and 7, the issue disappear.

I doubt the issue is related to wayland, my window manager is hyprland.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Dec 8, 2023

It is related to wayland and more specifically to how wl-copy works,
easily confirmed by running kitty with linux_display_backend x11 in
kitty.conf. As I said for nvim, use osc52 instead and you will be fine.
In this case instead of using wl-copy use kitten clipboard, which uses osc52 under the hood instead of talking to the wayland compositor directly unlike wl-copy

echo hello | kitten clipboard

@kovidgoyal
Copy link
Owner

Oh and incidentally your reproduction steps dont work on either gnome or kde under wayland, They work only with wl-roots based compositors. So maybe report it to sway or wl-roots, perhaps they can tell us what the issue is.

@ch3n9w
Copy link
Author

ch3n9w commented Dec 8, 2023

Thanks for your advice! A feasible mitigation method at this stage is not to use wl-clipboard in kitty and modify g:clipboard in neovim, which solves my issue.

vim.opt.clipboard = 'unnamed'
vim.g.clipboard = {
    name = "kittyClipboard",
    copy = {
        ["*"] = {"kitty","+kitten", "clipboard"},
        ["+"] = {"kitty","+kitten", "clipboard"},
    },
    paste = {
        ["*"] = { "kitty","+kitten", "clipboard", "--get-clipboard" },
        ["+"] = { "kitty","+kitten", "clipboard", "--get-clipboard" },
    },
    cache_enabled = 1,
}

@kovidgoyal kovidgoyal reopened this Dec 8, 2023
donovanglover added a commit to donovanglover/nix-config that referenced this issue Mar 30, 2024
This fixes an issue where copying text would break until changing
workspaces and consequently windows.

This *was* fixed in 0.32.0 as a result of [1], however kitty 0.33.1 with
the recent fontconfig workaround patch[2] ends up showing CJK characters
with a very thin weight, causing them to be inconsistent relative to the
surrounding text and more difficult to read.

[1]: kovidgoyal/kitty#6890
[2]: kovidgoyal/kitty@d2c21ee
@life5ign
Copy link

For reference, this was reported on tmux-yank: tmux-plugins/tmux-yank#151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants