Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(picker): allow appending original window's file name/path/dir to prompt #3398

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lua/telescope/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,34 @@ actions.insert_original_cline = function(prompt_bufnr)
current_picker:set_prompt(current_picker.original_cline, false)
end

--- Insert the file path of buffer in the original (pre-Telescope) window
---@param prompt_bufnr number: The prompt bufnr
actions.insert_original_file_path = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:set_prompt(current_picker.original_file_path, false)
end

--- Insert the file name of buffer in the original (pre-Telescope) window
---@param prompt_bufnr number: The prompt bufnr
actions.insert_original_file_name = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:set_prompt(current_picker.original_file_name, false)
end

--- Insert the bare file name of buffer in the original (pre-Telescope) window
---@param prompt_bufnr number: The prompt bufnr
actions.insert_original_file_bare_name = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:set_prompt(current_picker.original_file_bare_name, false)
end

--- Insert the directory of file in the original (pre-Telescope) window
---@param prompt_bufnr number: The prompt bufnr
actions.insert_original_file_dir = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:set_prompt(current_picker.original_file_dir, false)
end

actions.nop = function(_) end

actions.mouse_click = function(prompt_bufnr)
Expand Down
4 changes: 4 additions & 0 deletions lua/telescope/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ mappings.default_mappings = config.values.default_mappings
["<C-r><C-a>"] = actions.insert_original_cWORD,
["<C-r><C-f>"] = actions.insert_original_cfile,
["<C-r><C-l>"] = actions.insert_original_cline,
["<C-r><C-p>"] = actions.insert_original_file_path,
["<C-r><C-n>"] = actions.insert_original_file_name,
["<C-r><C-b>"] = actions.insert_original_file_bare_name,
["<C-r><C-d>"] = actions.insert_original_file_dir,

-- disable c-j because we dont want to allow new lines #2123
["<C-j>"] = actions.nop,
Expand Down
4 changes: 4 additions & 0 deletions lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ function Picker:find()
_, 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)
_, self.original_file_path = pcall(vim.fn.expand, "%")
_, self.original_file_name = pcall(vim.fn.expand, "%:t")
_, self.original_file_bare_name = pcall(vim.fn.expand, "%:t:r")
_, self.original_file_dir = pcall(vim.fn.expand, "%:h")

-- User autocmd run it before create Telescope window
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeFindPre" })
Expand Down
Loading