feat(picker): allow appending original window cword to prompt (#2878)
* feat(picker): allow appending original window cword to prompt * add default mapping and document * [docgen] Update doc/telescope.txt skip-checks: true * add mapping to README also format README * oops * [docgen] Update doc/telescope.txt skip-checks: true --------- Co-authored-by: Github Actions <actions@github>
This commit is contained in:
@@ -1484,6 +1484,13 @@ actions.delete_mark = function(prompt_bufnr)
|
||||
end)
|
||||
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
|
||||
|
||||
actions.nop = function(_) end
|
||||
|
||||
-- ==================================================
|
||||
|
||||
@@ -164,6 +164,7 @@ mappings.default_mappings = config.values.default_mappings
|
||||
["<C-/>"] = actions.which_key,
|
||||
["<C-_>"] = actions.which_key, -- keys from pressing <C-/>
|
||||
["<C-w>"] = { "<c-s-w>", type = "command" },
|
||||
["<C-r><C-w>"] = actions.insert_original_cword,
|
||||
|
||||
-- disable c-j because we dont want to allow new lines #2123
|
||||
["<C-j>"] = actions.nop,
|
||||
|
||||
@@ -529,6 +529,7 @@ function Picker:find()
|
||||
self:reset_selection()
|
||||
|
||||
self.original_win_id = a.nvim_get_current_win()
|
||||
self.original_cword = vim.fn.expand "<cword>"
|
||||
|
||||
-- User autocmd run it before create Telescope window
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeFindPre" })
|
||||
@@ -845,7 +846,13 @@ function Picker:delete_selection(delete_cb)
|
||||
end, 50)
|
||||
end
|
||||
|
||||
function Picker:set_prompt(text)
|
||||
---@param text string text to set as prompt
|
||||
---@param reset boolean? whether to replace prompt with text entirely or just append
|
||||
function Picker:set_prompt(text, reset)
|
||||
reset = vim.F.if_nil(reset, true)
|
||||
if not reset then
|
||||
text = self:_get_prompt() .. text
|
||||
end
|
||||
self:reset_prompt(text)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user