Skip to content

Commit

Permalink
feat: config option for system clipboard register (#179)
Browse files Browse the repository at this point in the history
if `opt.clipboard == ""` (because we want yanky to sync with system but
    not in the primary position) then the `*` register is used, with no
    way to choose `+`. So simply we add the necessary config option.
  • Loading branch information
IndianBoy42 committed May 22, 2024
1 parent 396ff7e commit 835bc40
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Yanky comes with the following defaults:
},
system_clipboard = {
sync_with_ring = true,
clipboard_register = nil,
},
highlight = {
on_put = true,
Expand Down Expand Up @@ -280,6 +281,17 @@ If `&clipboard` is empty, if you yank something outside of Neovim, this will be
the first value you'll have when cycling through the ring. Basicly, you can do
`p` and then `<c-p>` to paste yanked text.

Note that `clipboard == unnamed` uses the primary selection of the system (see
`:h clipbard` for more details) which is updated on selection, not on copy/yank.
Also note that the syncing happens when neovim gains focus.

### `system_clipboard.clipboard_register`

Default: `nil` use `&clipboard`

Choose the register that is synced with ring (from above). If `&clipboard` is
empty then `*` is used.

### `ring.update_register_on_cycle`

Default: `false`
Expand Down
1 change: 1 addition & 0 deletions lua/yanky/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local default_values = {
},
system_clipboard = {
sync_with_ring = true,
clipboard_register = nil,
},
highlight = {
on_put = true,
Expand Down
5 changes: 3 additions & 2 deletions lua/yanky/system_clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local system_clipboard = {

function system_clipboard.setup()
system_clipboard.config = require("yanky.config").options.system_clipboard
system_clipboard.config.clipboard_register = system_clipboard.config.clipboard_register or utils.get_system_register()
system_clipboard.history = require("yanky.history")

if system_clipboard.config.sync_with_ring then
Expand Down Expand Up @@ -44,11 +45,11 @@ function system_clipboard.setup()
end

function system_clipboard.on_focus_lost()
system_clipboard.state.reg_info_on_focus_lost = utils.get_register_info(utils.get_system_register())
system_clipboard.state.reg_info_on_focus_lost = utils.get_register_info(system_clipboard.config.clipboard_register)
end

function system_clipboard.on_focus_gained()
local new_reg_info = utils.get_register_info(utils.get_system_register())
local new_reg_info = utils.get_register_info(system_clipboard.config.clipboard_register)

if
system_clipboard.state.reg_info_on_focus_lost ~= nil
Expand Down
1 change: 0 additions & 1 deletion lua/yanky/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function utils.get_system_register()
if vim.tbl_contains(clipboardFlags, "unnamedplus") then
return "+"
end

return "*"
end

Expand Down

0 comments on commit 835bc40

Please sign in to comment.