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.11k stars 173 forks source link

feature: make the other jump actions also fold on a node #479

Closed NicoElbers closed 4 weeks ago

NicoElbers commented 4 weeks ago

Did you check the docs?

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

As far as I've found, it's currently not possible to combine folding a node and the "jump_close" functionality

Describe the solution you'd like

Adding the below code after "jump_close", "jump_split" and "jump_vsplit" here

elseif ctx.node then
  self:fold(ctx.node)
end

Describe alternatives you've considered

Alternatively allow users to create their own actions, this would be more flexible but it also may be a little overkill.

Additional context

No response

folke commented 4 weeks ago

If it's an action you want to execute from within the trouble window, then you can already do that. See the config for the two filtering examples.

If not, you can just add new actions to require('trouble.config.actions').actions

Or you can do any of these:

-- pass an action function as key
require("trouble")[function()
  dd("foo")
end]({ mode = "diagnostics" })

-- open trouble and do an action
local view = require(trouble).open(opts)
if view then
  view:action(action, opts) -- action is a string or function like in the actions
end

-- just use the trouble api
local view = require(trouble).open(opts)
if view then
  view:wait(function()
    view.win:focus()
  end)
end
NicoElbers commented 4 weeks ago

Ah, I completely missed this. Thank you for the quick reply!

folke commented 4 weeks ago

Docs are missing on these things. Will write some soon :)