nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.98k stars 837 forks source link

Change picker after it's open and maintain text input #2160

Open KiLLeRRaT opened 2 years ago

KiLLeRRaT commented 2 years ago

Hope I didn't miss a feature in the documentation, I did try to look and found nothing.

I constantly find myself opening the incorrect picker by accident. It would be awesome if you could easily jump to another picker with the old one still open, maintaining your text that you've typed.

I'd open the file picker, and enter my string, then realise I need to actually search file contents, so I want to hit a key to jump to the live_grep picker, and keep what I've typed.

Thanks for some great software!

KiLLeRRaT commented 1 year ago

Anyone have any thoughts on this, or how to being to implement this somehow?

DeadlySquad13 commented 1 year ago

Anyone have any thoughts on this, or how to being to implement this somehow?

I've been searching for something like this as I need it in my project too. I want to change between file_browser and file_finder on the fly because sometimes I need a fully flattened view for quick file detection. To solve my needs I've researched a little bit and found these links. I'm just going to test them, hopefully they will be useful for you too:

geier commented 1 year ago

see also https://github.com/nvim-telescope/telescope.nvim/issues/576

Sleepful commented 1 year ago

The fuzzy_refine for live_grep is likely a very good spot to look into ways of doing this type of action:

https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/builtin/__files.lua#L156-L159

ervandew commented 1 week ago

If it helps anyone, I added the following function to my config to grab the current prompt for any open telescope prompt on the current tab, otherwise returning an empty string if no current prompt exists:

local current_prompt_text = function()
  for _, bufnr in ipairs(vim.fn.tabpagebuflist()) do
    if vim.bo[bufnr].filetype == 'TelescopePrompt' then
      local action_state = require('telescope.actions.state')
      return action_state.get_current_picker(bufnr):_get_prompt()
    end
  end
  return ''
end

Then you can use that to set default_text when opening a picker. Eg:

vim.keymap.set('n', '<leader>ff', function()
  builtin.find_files({
    default_text = current_prompt_text(),
  })
end)