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 <cWORD>, <cfile> and cursor line to prompt #3134

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(picker): allow appending original window cWORD and cline(cursor …
…line) to prompt

Change-Id: I783eb105975e3720a268533269400dc8d0778d41
  • Loading branch information
younger-1 committed May 27, 2024
commit ff4ad0ce1628187f69b9fb02a0c2b988f211afa1
10 changes: 10 additions & 0 deletions lua/telescope/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,16 @@ actions.insert_original_cword = function(prompt_bufnr)
current_picker:set_prompt(current_picker.original_cword, false)
end

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.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)
Expand Down
2 changes: 2 additions & 0 deletions lua/telescope/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ 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-e>"] = actions.insert_original_cWORD,
Conni2461 marked this conversation as resolved.
Show resolved Hide resolved
["<C-r><C-l>"] = actions.insert_original_cline,

-- disable c-j because we dont want to allow new lines #2123
["<C-j>"] = actions.nop,
Expand Down
2 changes: 2 additions & 0 deletions lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ 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_cline = pcall(vim.trim, vim.api.nvim_get_current_line())
Conni2461 marked this conversation as resolved.
Show resolved Hide resolved

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