Skip to content

fix(#2535): TextYankPost event sends vim.v.event #2734

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

Merged
merged 4 commits into from
Mar 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lua/nvim-tree/actions/fs/copy-paste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,24 @@ end
---@param content string
local function copy_to_clipboard(content)
local clipboard_name
local reg
if M.config.actions.use_system_clipboard == true then
vim.fn.setreg("+", content)
vim.fn.setreg('"', content)
clipboard_name = "system"
reg = "+"
else
vim.fn.setreg('"', content)
vim.fn.setreg("1", content)
clipboard_name = "neovim"
reg = "1"
end

vim.api.nvim_exec_autocmds("TextYankPost", {})
-- manually firing TextYankPost does not set vim.v.event
-- workaround: create a scratch buffer with the clipboard contents and send a yank command
local temp_buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_text(temp_buf, 0, 0, 0, 0, { content })
vim.api.nvim_buf_call(temp_buf, function()
vim.cmd(string.format('normal! "%sy$', reg))
end)
vim.api.nvim_buf_delete(temp_buf, {})

notify.info(string.format("Copied %s to %s clipboard!", content, clipboard_name))
end

Expand Down