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

perf: speed up default register determination #207

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
25 changes: 14 additions & 11 deletions lua/yanky/utils.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
local utils = {}

function utils.get_default_register()
local clipboard_tool = vim.fn["provider#clipboard#Executable"]()
if not clipboard_tool or "" == clipboard_tool then
return '"'
end

local clipboard_flags = vim.split(vim.api.nvim_get_option("clipboard"), ",")
local clipboard_flags = vim.split(vim.api.nvim_get_option_value("clipboard", {}), ",")
local selected_register = '"'

if vim.tbl_contains(clipboard_flags, "unnamedplus") then
return "+"
selected_register = "+"
end

if vim.tbl_contains(clipboard_flags, "unnamed") then
return "*"
selected_register = "*"
end

return '"'
if selected_register ~= '"' then
local clipboard_tool = vim.fn["provider#clipboard#Executable"]()
if not clipboard_tool or "" == clipboard_tool then
return '"'
end
end

return selected_register
end

function utils.get_system_register()
local clipboardFlags = vim.split(vim.api.nvim_get_option("clipboard"), ",")
local clipboard_flags = vim.split(vim.api.nvim_get_option_value("clipboard", {}), ",")

if vim.tbl_contains(clipboardFlags, "unnamedplus") then
if vim.tbl_contains(clipboard_flags, "unnamedplus") then
return "+"
end
return "*"
Expand Down
Loading