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

Add option to not close picker on losing focus #1988

Closed
Zane- opened this issue Jun 6, 2022 · 9 comments
Closed

Add option to not close picker on losing focus #1988

Zane- opened this issue Jun 6, 2022 · 9 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@Zane-
Copy link

Zane- commented Jun 6, 2022

Is your feature request related to a problem? Please describe.
If a picker shows some information that you may need to reference while editing, it would be nice to be able to switch focus off of the picker and not have it close.

Describe the solution you'd like
Add some sort of option to pickers to enable this behavior.

@Zane- Zane- added the enhancement Enhancement to performance, inner workings or existent features label Jun 6, 2022
@Conni2461
Copy link
Member

is this a dup of #1967 If yes i would like to close this.

@Zane-
Copy link
Author

Zane- commented Jun 6, 2022

I wouldn't say it's a duplicate, their request seems a lot different (ie keeping the picker open when selecting the result, isn't this already possible by remapping the default select action?)

@miversen33
Copy link

Ya this is different than that request, though I am unsure how it would be used (as the floating window tends to take up enough screen real estate that I dont imagine you can do much without it being in the way).

That said, I dont see this being overly complicated to do as there is no logic (as far as I can tell) that auto closes the floating window. This means that the close happens "manually" (meaning telescope has to close the floating buffer on its own as opposed to Neovim closing it via an event callback).

I dont really know how that logic would work though. Allow a user to set an option that says "dont close on selection"? Add a keymap for closing the floating window and infer that that being set means that the window wont close on selection?

It seems a bit vague imo. Have any ideas on how you would like to see that implemented? @Zane-

@Zane-
Copy link
Author

Zane- commented Jun 6, 2022

A floating window taking up real estate is completely dependent on how your telescope is themed though. See this example:

preview

In this case, it would be ideal to have the answer be visible after clicking back onto your main buffer, so you can copy it down.

I'm not sure what Neovim does when you click off of a popup window, but if there's a way to not auto-close it when you click off of it, then just adding an option to the picker options to not close on losing focus would be nice:

opts = {
  close_on_lose_focus = false.
}.
picker.new(opts, ...)

@miversen33
Copy link

miversen33 commented Jun 6, 2022

A floating window taking up real estate is completely dependent on how your telescope is themed though. See this example:

This is a valid point. I will poke about in the internals of this tonight/this weekend (depends on how motivated I feel lol).

That said, this doesn't answer the second half of the question. If we are removing the ability to auto close (if an option is set), there must be a way to close the floating window manually. The underlying code exists for this (action.close), but from a cursory glance, I dont see it bound to anything in particular (note, I am not putting alot of effort into researching this at this time, this is just cursory info), so along with this consideration we would also need to expose a new keymapping and enforce it if the option close_on_lose_focus = false is set. Otherwise there is no obvious way to close out Telescope.

@Conni2461 / @fdschmidt93 correct me if I am off base :)

@Conni2461
Copy link
Member

close is currently bound to <esc> in normal and <c-c> in insert mode.

What we can do is not register the autocmds that close telescope on focus leave but i dont actually want to support that. It could just lead to a bunch of different problems down the road. We merged a couple of time "simple changes" that caused issues after issues after issues. Thats why i pointed to #1967. Some way to do that but in a more structured way with a lot of autocmds, which prevent focus on results window or preview window. And i still thinks its basically the same. #1967 wants a persistent telescope split where you can hop in and out. And you want to hop out of telescope window but never back in?! Your feature request is pretty short. And hasn't even answered all questions.

The only way i would implement that if we prefix that option with __ and not document it. Basically saying, this is not really supported and can lead to problems.

@fdschmidt93
Copy link
Member

fdschmidt93 commented Jun 6, 2022

I haven't read through this issue as a whole, but I don't think the original request should be a configurable option for the time being for telescope. The primary reason is that the general behavior is not super well defined and likely very user specific.

In any case, this is perfectly achievable with hacks already

local my_action = function(prompt_bufnr)
  local current_picker = require "telescope.actions.state".get_current_picker(prompt_bufnr)
  vim.cmd(string.format("noautocmd lua vim.api.nvim_set_current_win(%s)", current_picker.original_win_id))
end

Getting prompt buffer back

vim.tbl_filter(function(b) return vim.bo[b].filetype == "TelescopePrompt" end, vim.api.nvim_list_bufs())[1]

barring any typos/mini bugs introduced by on-the-fly typing should work. From a core repo persepective, I'll be honest, this introduces more headache than I would assume anyone of the team would be willing to incur for such a feature.

@Conni2461
Copy link
Member

Conni2461 commented Jun 6, 2022

One problem that comes to my mind instantly is that if you open a new telescope picker, we close the previous one. So yeah do you to be able to switch buffers while having your telescope "session" open? Because that needs some rework as well. And might lead to even more problems

@Zane-
Copy link
Author

Zane- commented Jun 6, 2022

Alright, if it would cause too much headache, feel free to close.

@Zane- Zane- closed this as completed Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests

4 participants