Skip to content

Commit d8d3a15

Browse files
fix(#2535): TextYankPost event sends vim.v.event (#2734)
* fix TextYankPost event * Update lua/nvim-tree/actions/fs/copy-paste.lua Co-authored-by: Alexander Courtis <[email protected]> * fix format string * style --------- Co-authored-by: Alexander Courtis <[email protected]>
1 parent ddd1d6e commit d8d3a15

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lua/nvim-tree/actions/fs/copy-paste.lua

+12-5
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,24 @@ end
276276
---@param content string
277277
local function copy_to_clipboard(content)
278278
local clipboard_name
279+
local reg
279280
if M.config.actions.use_system_clipboard == true then
280-
vim.fn.setreg("+", content)
281-
vim.fn.setreg('"', content)
282281
clipboard_name = "system"
282+
reg = "+"
283283
else
284-
vim.fn.setreg('"', content)
285-
vim.fn.setreg("1", content)
286284
clipboard_name = "neovim"
285+
reg = "1"
287286
end
288287

289-
vim.api.nvim_exec_autocmds("TextYankPost", {})
288+
-- manually firing TextYankPost does not set vim.v.event
289+
-- workaround: create a scratch buffer with the clipboard contents and send a yank command
290+
local temp_buf = vim.api.nvim_create_buf(false, true)
291+
vim.api.nvim_buf_set_text(temp_buf, 0, 0, 0, 0, { content })
292+
vim.api.nvim_buf_call(temp_buf, function()
293+
vim.cmd(string.format('normal! "%sy$', reg))
294+
end)
295+
vim.api.nvim_buf_delete(temp_buf, {})
296+
290297
notify.info(string.format("Copied %s to %s clipboard!", content, clipboard_name))
291298
end
292299

0 commit comments

Comments
 (0)