feat(picker): allow appending original window <cWORD>, <cfile> and cursor line to prompt (#3134)
This commit is contained in:
@@ -1496,6 +1496,27 @@ actions.insert_original_cword = function(prompt_bufnr)
|
||||
current_picker:set_prompt(current_picker.original_cword, false)
|
||||
end
|
||||
|
||||
--- Insert the WORD under the cursor of the original (pre-Telescope) window
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
actions.insert_original_cWORD = function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
current_picker:set_prompt(current_picker.original_cWORD, false)
|
||||
end
|
||||
|
||||
--- Insert the file under the cursor of the original (pre-Telescope) window
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
actions.insert_original_cfile = function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
current_picker:set_prompt(current_picker.original_cfile, false)
|
||||
end
|
||||
|
||||
--- Insert the line under the cursor of the original (pre-Telescope) window
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
actions.insert_original_cline = function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
current_picker:set_prompt(current_picker.original_cline, false)
|
||||
end
|
||||
|
||||
actions.nop = function(_) end
|
||||
|
||||
actions.mouse_click = function(prompt_bufnr)
|
||||
|
||||
@@ -176,6 +176,9 @@ mappings.default_mappings = config.values.default_mappings
|
||||
["<C-_>"] = actions.which_key, -- keys from pressing <C-/>
|
||||
["<C-w>"] = { "<c-s-w>", type = "command" },
|
||||
["<C-r><C-w>"] = actions.insert_original_cword,
|
||||
["<C-r><C-a>"] = actions.insert_original_cWORD,
|
||||
["<C-r><C-f>"] = actions.insert_original_cfile,
|
||||
["<C-r><C-l>"] = actions.insert_original_cline,
|
||||
|
||||
-- disable c-j because we dont want to allow new lines #2123
|
||||
["<C-j>"] = actions.nop,
|
||||
|
||||
@@ -537,6 +537,10 @@ function Picker:find()
|
||||
|
||||
self.original_win_id = a.nvim_get_current_win()
|
||||
_, self.original_cword = pcall(vim.fn.expand, "<cword>")
|
||||
_, self.original_cWORD = pcall(vim.fn.expand, "<cWORD>")
|
||||
_, self.original_cfile = pcall(vim.fn.expand, "<cfile>")
|
||||
_, self.original_cline = pcall(vim.api.nvim_get_current_line)
|
||||
_, self.original_cline = pcall(vim.trim, self.original_cline)
|
||||
|
||||
-- User autocmd run it before create Telescope window
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeFindPre" })
|
||||
|
||||
Reference in New Issue
Block a user