Skip to content

Commit

Permalink
feat: add option to control cycling of result list (#302)
Browse files Browse the repository at this point in the history
Add new cycle_results option (default: true, the current behavior), to
control whether to cycle the results list when reaching the beginning or
end of the list.
  • Loading branch information
willnorris committed Jun 24, 2023
1 parent a3372bd commit e7805dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Trouble comes with the following defaults:
fold_closed = "", -- icon used for closed folds
group = true, -- group results by file
padding = true, -- add an extra new line on top of the list
cycle_results = true, -- cycle item list when reaching beginning or end of list
action_keys = { -- key mappings for actions in the trouble list
-- map to {} to remove a mapping, for example:
-- close = {},
Expand Down
1 change: 1 addition & 0 deletions lua/trouble/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local defaults = {
severity = nil, -- nil (ALL) or vim.diagnostic.severity.ERROR | WARN | INFO | HINT
fold_open = "", -- icon used for open folds
fold_closed = "", -- icon used for closed folds
cycle_results = true, -- cycle item list when reaching beginning or end of list
action_keys = { -- key mappings for actions in the trouble list
close = "q", -- close the list
cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
Expand Down
8 changes: 6 additions & 2 deletions lua/trouble/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ function View:next_item(opts)
local line = opts.first and 0 or self:get_line() + 1

if line > #self.items then
self:first_item(opts)
if config.options.cycle_results then
self:first_item(opts)
end
else
for i = line, vim.api.nvim_buf_line_count(self.buf), 1 do
if self.items[i] and not (opts.skip_groups and self.items[i].is_file) then
Expand All @@ -406,7 +408,9 @@ function View:previous_item(opts)
for i = 0, vim.api.nvim_buf_line_count(self.buf), 1 do
if self.items[i] then
if line < i + (opts.skip_groups and 1 or 0) then
self:last_item(opts)
if config.options.cycle_results then
self:last_item(opts)
end
return
end
break
Expand Down

0 comments on commit e7805dc

Please sign in to comment.