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

Focus current line when opening Trouble

Open DanielPower opened this issue 3 years ago • 8 comments

If my cursor is on a line with an error when I open Trouble, I'd like trouble to show the errors on that line.

Prerequisite: Have your cursor on a line that has an error on it. Then run :Trouble

Current behaviour: Trouble will open, and select the first error in the workspace. Your cursor will jump away from its current position to the file/location of the first error listed in Trouble.

Desired behaviour: Trouble should recognize that there is an error on the current line, and initially focus that error. If not too difficult, it would be nice if it found the nearest error to the cursor, so if you were next to an error but not on it, Trouble would still jump to that error. But that's not quite as important to me.

DanielPower avatar May 17 '21 14:05 DanielPower

totally makes sense. I'll add it at some point.

folke avatar May 18 '21 12:05 folke

This is also annoying when using require("trouble").next(...) and require("trouble").previous(...) without having Trouble focused. Once I switch focus back to Trouble, I'm at the first item again. Would you accept PRs for this?

tom-anders avatar Jul 22 '21 06:07 tom-anders

@tom-anders yes! Sorry, didn't have the time yet to work on this myself. A PR would be much appreciated.

folke avatar Jul 22 '21 06:07 folke

Cool, I'll see if I find some time to work on this over the weekend.

Btw, the use case I described in my comment above actually already works, looks like it was just a problem with my configuration. However, I think it would be cool to have the current line highlighted in Trouble in that case, even when Trouble is not focused (just like the quickfix window does). Know what I mean?

tom-anders avatar Jul 22 '21 07:07 tom-anders

Any news on this? At least setting auto_preview = false prevents the jumping around.

AlexvZyl avatar Oct 08 '22 20:10 AlexvZyl

It would be nice to extend this to lsp_references and other actions too. So for example when you open Trouble references in the Trouble window the current reference would be nice to be selected instead of the first one.

yavorski avatar Jun 02 '23 14:06 yavorski

This PR I opened should probably help with this issue.

Probably it needs some adjustments (it's been more than a year since I opened it)

bellini666 avatar Jun 02 '23 20:06 bellini666

I'm definitely down with this to match the ALE style. I'm really surprised more people don't like this, and would rather have a popup window

9mm avatar Aug 10 '23 01:08 9mm

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev

folke avatar Mar 29 '24 07:03 folke