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

feat: enable looping during next/prev #232

Merged
merged 1 commit into from
Feb 20, 2023
Merged

feat: enable looping during next/prev #232

merged 1 commit into from
Feb 20, 2023

Conversation

jrnxf
Copy link
Contributor

@jrnxf jrnxf commented Nov 17, 2022

This PR accomplishes two goals:

  1. Allow for looping through results in the Trouble buffer. The previous action on the first result will loop you to the last result, whereas the next action on the last result will loop you to the first.
Screen.Recording.2022-11-16.at.11.36.42.PM.mov
  1. Exposes the is_open method. Useful for creating trouble-aware mappings. For example, I want <C-j> to open trouble if not already opened. If it is open, then have it take me to the next result like normal.
km.nnoremap('<C-j>', function()
  if not trouble.is_open() then
    trouble.open()
  else
    trouble.next({ skip_groups = true, jump = true })
  end
end)
km.nnoremap('<C-k>', function()
  if not trouble.is_open() then
    trouble.open()
  else
    trouble.previous({ skip_groups = true, jump = true })
  end
end)

@jrnxf jrnxf changed the title Enable looping during next/prev / expose is_open feat: enable looping during next/prev / expose is_open Nov 17, 2022
@jrnxf
Copy link
Contributor Author

jrnxf commented Feb 18, 2023

@folke I saw you add expose the is_open method earlier - ty for that! Could I get your thoughts on this PR when you get the chance?

Copy link
Owner

@folke folke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

You can remove the loop config option and just make it the default. Thanks!

@jrnxf jrnxf changed the title feat: enable looping during next/prev / expose is_open feat: enable looping during next/prev Feb 20, 2023
@jrnxf
Copy link
Contributor Author

jrnxf commented Feb 20, 2023

Updated! I also exposed the is_open directly on the Trouble module like the rest of the methods, since it seemed odd to have it be the only one that was exposed differently

@folke folke merged commit fc4c0f8 into folke:main Feb 20, 2023
@folke
Copy link
Owner

folke commented Feb 20, 2023

Awesome, thanks!

@tom-anders
Copy link
Contributor

Is there an easy way to turn off this new behavior? For me it's pretty annoying and unexpected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants