feat: copy/paste to system clipboard (#559)

* feat: copy/paste to system clipboard on macOS

* stylua

* feat: copy/paste to system clipboard on linux

* force mime type

* fix string.gsub

* vim.uv or vim.loop

* fix stylua

* support gnome directly

* support wayland

* refactor: extract clipboard actions into separate file

* fix: copy/paste in KDE

* refactor: simplify file loading

* fix: copy/paste on x11

* fix: better error message when clipboard command not found

* fix: paste on mac

* fix: pasting in Gnome

* feat: support pasting multiple files

* feat: support copying multiple files to clipboard

---------

Co-authored-by: Steve Walker <65963536+etherswangel@users.noreply.github.com>
Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
This commit is contained in:
Steve Walker 2025-03-20 23:19:18 +08:00 committed by GitHub
parent 8649818fb2
commit 4c9bdf0d83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 427 additions and 35 deletions

View file

@ -30,8 +30,6 @@ local M = {}
---@field filter_action? fun(action: oil.Action): boolean When present, filter out actions as they are created
---@field filter_error? fun(action: oil.ParseError): boolean When present, filter out errors from parsing a buffer
local load_oil_buffer
---Get the entry on a specific line (1-indexed)
---@param bufnr integer
---@param lnum integer
@ -593,7 +591,7 @@ M.open_preview = function(opts, callback)
-- If we called open_preview during an autocmd, then the edit command may not trigger the
-- BufReadCmd to load the buffer. So we need to do it manually.
if util.is_oil_bufnr(filebufnr) then
load_oil_buffer(filebufnr)
M.load_oil_buffer(filebufnr)
end
vim.api.nvim_set_option_value("previewwindow", true, { scope = "local", win = 0 })
@ -1013,8 +1011,9 @@ local function restore_alt_buf()
end
end
---@private
---@param bufnr integer
load_oil_buffer = function(bufnr)
M.load_oil_buffer = function(bufnr)
local config = require("oil.config")
local keymap_util = require("oil.keymap_util")
local loading = require("oil.loading")
@ -1218,7 +1217,7 @@ M.setup = function(opts)
pattern = scheme_pattern,
nested = true,
callback = function(params)
load_oil_buffer(params.buf)
M.load_oil_buffer(params.buf)
end,
})
vim.api.nvim_create_autocmd("BufWriteCmd", {
@ -1388,7 +1387,7 @@ M.setup = function(opts)
local util = require("oil.util")
local scheme = util.parse_url(params.file)
if config.adapters[scheme] and vim.api.nvim_buf_line_count(params.buf) == 1 then
load_oil_buffer(params.buf)
M.load_oil_buffer(params.buf)
end
end,
})
@ -1397,7 +1396,7 @@ M.setup = function(opts)
if maybe_hijack_directory_buffer(bufnr) and vim.v.vim_did_enter == 1 then
-- manually call load on a hijacked directory buffer if vim has already entered
-- (the BufReadCmd will not trigger)
load_oil_buffer(bufnr)
M.load_oil_buffer(bufnr)
end
end