folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.44k stars 177 forks source link

feature: close all views #456

Closed abhinavnatarajan closed 4 months ago

abhinavnatarajan commented 4 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

In Trouble v2, if some view was open and I used :TroubleToggle someotherview, the active view would be closed and the new view would be opened. This meant that I could use trouble as a console with a fixed window position, with at most one Trouble window active at any given moment. In Trouble v3, toggling a new view does not close currently active views, so for example if the diagnostics view is open and I also open the qflist then I have two trouble windows open.

Describe the solution you'd like

Allow passing in "*" as a mode parameter for trouble.close(). That way I can close all windows, and use this in the keybind I have for toggling views. Ideally this should also be allowed for trouble.is_open() to accommodate setups with more nuanced window management.

Describe alternatives you've considered

Technically my issue can be solved by calling trouble.close() for every possible view, but this is unecessarily verbose, and brittle because the code would have to be modified whenever a new view is added to Trouble.

Additional context

No response

folke commented 4 months ago

If you call either close or is_open without any options, it will check if any view is open or will close the most recent view.

To close all:

local view = trouble.close()
while view do
  view = trouble.close()
end