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

@ -25,38 +25,54 @@ M.escape_filename = function(filename)
return ret
end
local _url_escape_chars = {
[" "] = "%20",
["$"] = "%24",
["&"] = "%26",
["`"] = "%60",
[":"] = "%3A",
["<"] = "%3C",
["="] = "%3D",
[">"] = "%3E",
["?"] = "%3F",
["["] = "%5B",
["\\"] = "%5C",
["]"] = "%5D",
["^"] = "%5E",
["{"] = "%7B",
["|"] = "%7C",
["}"] = "%7D",
["~"] = "%7E",
[""] = "%22",
[""] = "%27",
["+"] = "%2B",
[","] = "%2C",
["#"] = "%23",
["%"] = "%25",
["@"] = "%40",
["/"] = "%2F",
[";"] = "%3B",
local _url_escape_to_char = {
["20"] = " ",
["22"] = "",
["23"] = "#",
["24"] = "$",
["25"] = "%",
["26"] = "&",
["27"] = "",
["2B"] = "+",
["2C"] = ",",
["2F"] = "/",
["3A"] = ":",
["3B"] = ";",
["3C"] = "<",
["3D"] = "=",
["3E"] = ">",
["3F"] = "?",
["40"] = "@",
["5B"] = "[",
["5C"] = "\\",
["5D"] = "]",
["5E"] = "^",
["60"] = "`",
["7B"] = "{",
["7C"] = "|",
["7D"] = "}",
["7E"] = "~",
}
local _char_to_url_escape = {}
for k, v in pairs(_url_escape_to_char) do
_char_to_url_escape[v] = "%" .. k
end
-- TODO this uri escape handling is very incomplete
---@param string string
---@return string
M.url_escape = function(string)
return (string:gsub(".", _url_escape_chars))
return (string:gsub(".", _char_to_url_escape))
end
---@param string string
---@return string
M.url_unescape = function(string)
return (
string:gsub("%%([0-9A-Fa-f][0-9A-Fa-f])", function(seq)
return _url_escape_to_char[seq:upper()] or ("%" .. seq)
end)
)
end
---@param bufnr integer