diff --git a/README.md b/README.md index b9eb493..f23cd11 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,9 @@ Many familiar mapping patterns are set up as defaults. | `` | Send all items not filtered to quickfixlist (qflist) | | `` | Send all selected items to qflist | | `` | Insert cword in original window into prompt (insert mode) | +| `` | Insert cWORD in original window into prompt (insert mode) | +| `` | Insert cfile in original window into prompt (insert mode) | +| `` | Insert cline in original window into prompt (insert mode) | To see the full list of mappings, check out `lua/telescope/mappings.lua` and the `default_mappings` table. diff --git a/doc/telescope.txt b/doc/telescope.txt index f63162d..a38a88f 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -3393,6 +3393,30 @@ actions.insert_original_cword({prompt_bufnr}) *telescope.actions.insert_original {prompt_bufnr} (number) The prompt bufnr +actions.insert_original_cWORD({prompt_bufnr}) *telescope.actions.insert_original_cWORD()* + Insert the WORD under the cursor of the original (pre-Telescope) window + + + Parameters: ~ + {prompt_bufnr} (number) The prompt bufnr + + +actions.insert_original_cfile({prompt_bufnr}) *telescope.actions.insert_original_cfile()* + Insert the file under the cursor of the original (pre-Telescope) window + + + Parameters: ~ + {prompt_bufnr} (number) The prompt bufnr + + +actions.insert_original_cline({prompt_bufnr}) *telescope.actions.insert_original_cline()* + Insert the line under the cursor of the original (pre-Telescope) window + + + Parameters: ~ + {prompt_bufnr} (number) The prompt bufnr + + ================================================================================ ACTIONS_STATE *telescope.actions.state* diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index c8bef1d..3daaefd 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -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) diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index 90a4812..287cac9 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -176,6 +176,9 @@ mappings.default_mappings = config.values.default_mappings [""] = actions.which_key, -- keys from pressing [""] = { "", type = "command" }, [""] = actions.insert_original_cword, + [""] = actions.insert_original_cWORD, + [""] = actions.insert_original_cfile, + [""] = actions.insert_original_cline, -- disable c-j because we dont want to allow new lines #2123 [""] = actions.nop, diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 88e89cc..189e923 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -537,6 +537,10 @@ function Picker:find() self.original_win_id = a.nvim_get_current_win() _, self.original_cword = pcall(vim.fn.expand, "") + _, self.original_cWORD = pcall(vim.fn.expand, "") + _, self.original_cfile = pcall(vim.fn.expand, "") + _, 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" })