Register finder (#275)
builtin: Registers finder. view and edit vim registers.
This commit is contained in:
@@ -169,6 +169,45 @@ actions.set_command_line = function(prompt_bufnr)
|
||||
vim.cmd(entry.value)
|
||||
end
|
||||
|
||||
actions.edit_register = function(prompt_bufnr)
|
||||
local entry = actions.get_selected_entry(prompt_bufnr)
|
||||
local picker = actions.get_current_picker(prompt_bufnr)
|
||||
|
||||
vim.fn.inputsave()
|
||||
local updated_value = vim.fn.input("Edit [" .. entry.value .. "] ❯ ", entry.content)
|
||||
vim.fn.inputrestore()
|
||||
if updated_value ~= entry.content then
|
||||
vim.fn.setreg(entry.value, updated_value)
|
||||
entry.content = updated_value
|
||||
end
|
||||
|
||||
-- update entry in results table
|
||||
-- TODO: find way to redraw finder content
|
||||
for k, v in pairs(picker.finder.results) do
|
||||
if v == entry then
|
||||
v.content = updated_value
|
||||
end
|
||||
end
|
||||
-- print(vim.inspect(picker.finder.results))
|
||||
end
|
||||
|
||||
actions.paste_register = function(prompt_bufnr)
|
||||
local entry = actions.get_selected_entry(prompt_bufnr)
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
|
||||
-- ensure that the buffer can be written to
|
||||
if vim.api.nvim_buf_get_option(vim.api.nvim_get_current_buf(), "modifiable") then
|
||||
print("Paste!")
|
||||
-- substitute "^V" for "b"
|
||||
local reg_type = vim.fn.getregtype(entry.value)
|
||||
if reg_type:byte(1, 1) == 0x16 then
|
||||
reg_type = "b" .. reg_type:sub(2, -1)
|
||||
end
|
||||
vim.api.nvim_put({entry.content}, reg_type, true, true)
|
||||
end
|
||||
end
|
||||
|
||||
actions.run_builtin = function(prompt_bufnr)
|
||||
local entry = actions.get_selected_entry(prompt_bufnr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user