trouble.nvim icon indicating copy to clipboard operation
trouble.nvim copied to clipboard

feature: Remembering Current Entry State After Toggling Trouble Window

Open tummetott opened this issue 2 years ago • 11 comments

Did you check the docs?

  • [X] I have read all the trouble.nvim docs

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

Hello,

I have completely replaced my Quickfix list with Trouble, and I love its features. However, there is one thing that bothers me. Trouble doesn't seem to remember its current entry when I toggle it off and on again. In contrast, the native Quickfix window remembers its current entry when toggling with cclose and copen.

Describe the solution you'd like

Trouble remembers it's current entry

Describe alternatives you've considered

Additional context

No response

tummetott avatar Dec 11 '23 16:12 tummetott

Upvote!

belorenz avatar Dec 13 '23 15:12 belorenz

Upvote

simserino avatar Dec 14 '23 01:12 simserino

Upvote!

engebeni avatar Dec 14 '23 10:12 engebeni

Upvote

tylernewnoise avatar Dec 19 '23 20:12 tylernewnoise

Upvote! It would also be awesome to get the ability to call require("trouble").next({skip_groups = true, jump = true}); for the last active Trouble Instance, even if the Trouble list isn't toggled at the moment. The same way that you would use :cn or :cp with the quickfix-list while it's not opened. Maybe worth an issue..

juliangoetze avatar Feb 03 '24 21:02 juliangoetze

When i saw that trouble v3 is released, i was hoping to much this feature would be included. But apparently it doesn't. When toggeling the quickfix with require('trouble').toggle('quickfix'), there is always the first entry selected

tummetott avatar Mar 29 '24 09:03 tummetott

Added and enabled by default. Be aware that this setting might conflict with follow, so you may want to also set follow=false depending your use-case

folke avatar Mar 29 '24 10:03 folke

Not working for me.

consider this minimal config:

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    {
        "folke/trouble.nvim",
        branch = "dev",
        lazy = false,
        opts = {
            follow = false,
            restore = true,
            auto_preview = false,
            auto_refresh = false,
        },
    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Then I open nvim with: nvim -u repro.lua repro.lua

  1. :grep vim repro.lua Populates the qflist
  2. :Trouble quickfix toggle focus
  3. Go down a few entries and press <CR> to jump to a qf-entry
  4. :Trouble quickfix toggle
  5. :Trouble quickfix toggle --> cursorline is on the first line again

tummetott avatar Mar 29 '24 12:03 tummetott

Should be fixed now. The problem was that qf items did not have a unique id, so the check on re-open failed to find the previously selected entry

folke avatar Mar 29 '24 13:03 folke

unfortunately still not working with the same example

tummetott avatar Mar 29 '24 14:03 tummetott

Upvote! It would also be awesome to get the ability to call require("trouble").next({skip_groups = true, jump = true}); for the last active Trouble Instance, even if the Trouble list isn't toggled at the moment. The same way that you would use :cn or :cp with the quickfix-list while it's not opened. Maybe worth an issue..

UPVOTE!!!!

rgauselumifi avatar Apr 01 '24 21:04 rgauselumifi

Allright, I now used your repro and at least that should be fixed now.

Would be great if you can confirm!

folke avatar May 29 '24 18:05 folke

Allright, I now used your repro and at least that should be fixed now.

Would be great if you can confirm!

it works when toggeling the trouble window off and on once. if I toggle it off and on twice, the entry is lost.

additionally it also does not remember the entry when the trouble window resides in a edgy window and the whole edgy bar is closed with require('edgy').close(). When i afterwards toggle on the trouble window with :Trouble quickfix toggle, the entry is lost as well.

Last but not least, jumping to the next entry of the last toruble window when the trouble is closed with require("trouble").next({skip_groups = true, jump = true}); is not possible. should i open a new issue for the last feature request?

tummetott avatar May 30 '24 15:05 tummetott

I changed the way we track/restore positions, so that shoudl fix that toggle twice.

For me it all works with edgy, so maybe that also fixes that.

About that last thing, I dont fully understand what you mean?

folke avatar May 30 '24 15:05 folke

I changed the way we track/restore positions, so that shoudl fix that toggle twice.

yes that works now thank you

For me it all works with edgy, so maybe that also fixes that.

you are right, edgy is not the problem. The problem is that i advance the entries with: :lua require'trouble'.next({ jump = true }). I have a keymap for that. If I use the next() function, then the entry is not remembered. But when I jump with the cursor inside the trouble window, select an entry and press <CR>, then the entry is remembered after toggling.

tummetott avatar May 30 '24 17:05 tummetott

About that last thing, I dont fully understand what you mean?

in vanilla (n)vim, you can populate a quickfix list and jump to the next entry with :cnext. It does not matter if the qflist is open or closed, it works either way.

in trouble you can populate the trouble list (lets say the telescope list) and then jump to the next entry with :lua require'trouble'.next({mode = 'telescope', jump = true}). It works when the trouble window is open. when the trouble window is closed, it does not work, it only opens it. The expected behavior would be that the trouble window is not opened but the cursor jumps to the next entry.

tummetott avatar May 30 '24 17:05 tummetott

About that last thing, I dont fully understand what you mean?

in vanilla (n)vim, you can populate a quickfix list and jump to the next entry with :cnext. It does not matter if the qflist is open or closed, it works either way.

in trouble you can populate the trouble list (lets say the telescope list) and then jump to the next entry with :lua require'trouble'.next({mode = 'telescope', jump = true}). It works when the trouble window is open. when the trouble window is closed, it does not work, it only opens it. The expected behavior would be that the trouble window is not opened but the cursor jumps to the next entry.

Quite similar to the thing I mentioned above. Maybe this could be better explained in a dedicated issue..

juliangoetze avatar May 31 '24 05:05 juliangoetze