diff options
| author | Senghan Bright <senghan.bright@deltaprojects.com> | 2020-11-23 11:07:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-23 11:07:53 +0100 |
| commit | 124655608ff727ecee032bb2eb6f44014e8868eb (patch) | |
| tree | 3cb4a1d5b67487da6e44bc943f171687e46b7c82 /lua/telescope/actions/init.lua | |
| parent | 874139ee0b14fedfadca396884f166fc6eb34d4a (diff) | |
Register finder (#275)
builtin: Registers finder. view and edit vim registers.
Diffstat (limited to 'lua/telescope/actions/init.lua')
| -rw-r--r-- | lua/telescope/actions/init.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index c6f2f25..9dabfcb 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -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) |
