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

system clipboard support #58

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ use {
With `fzf-lua` only insert mode is supported and `fzf`-style key-syntax needs to be used.
You can also use the `custom` entry to specify custom actions to take on certain key-presses, see [below](#custom-actions) for more details.
NOTE: these are only set in the `telescope` buffer and you need to setup your own keybindings to for example open `telescope`.
* `enable_system_clipboard`: if set to `true`, the content in register `*` and
`+` will be stored.
NOTE: clipboard provider need to set up correctly in neovim, see `:help clipboard` for
more details

See screenshot section below for how the settings above might affect the looks.

Expand Down
25 changes: 25 additions & 0 deletions lua/neoclip/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ local function get_regtype(regtype)
end
end

local function get_register_event(register)
local event = vim.fn.getreginfo(register)
return event
end

M.handle_yank_post = function()
if neoclip.stopped then
return
Expand Down Expand Up @@ -94,4 +99,24 @@ M.delete = function(typ, entry)
storage.delete(typ, entry)
end

M.handle_system_yank = function ()
if neoclip.stopped then
return
end
if not settings.enable_system_clipboard then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this setting is needed anymore since a user just wouldn't trigger this function

return
end
for _, register in ipairs({'+', '*'}) do
local event = get_register_event(register)
if #event.regcontents ~= 0 then
if should_add(event) then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about extracting a function from the current handle_text_yank which takes and event table and does the check for should_add and neoclip.stopped and we don't need to check it in more than one place?

storage.insert({
regtype = get_regtype(event.regtype),
contents = event.regcontents,
filetype = vim.bo.filetype,
}, 'yanks')
end
end
end
end
return M
1 change: 1 addition & 0 deletions lua/neoclip/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local settings = {
history = 1000,
enable_persistent_history = false,
continuous_sync = false,
enable_system_clipboard = false,
db_path = vim.fn.stdpath("data") .. "/databases/neoclip.sqlite3",
filter = nil,
preview = true,
Expand Down