Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lua/trouble/config/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ local M = {
last = function(self, ctx)
self:move({ idx = -vim.v.count1, jump = ctx.opts.jump })
end,
-- next/prev file
next_file = function(self)
self:move({ next_file = true })
end,
prev_file = function(self)
self:move({ prev_file = true })
end,
-- Jump to the item if on an item, otherwise do nothing
jump_only = function(self, ctx)
if ctx.item then
Expand Down
2 changes: 2 additions & 0 deletions lua/trouble/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ local defaults = {
-- k = "prev",
["{"] = "prev",
["[["] = "prev",
["]f"] = "next_file",
["[f"] = "prev_file",
dd = "delete",
d = { action = "delete", mode = "v" },
i = "inspect",
Expand Down
27 changes: 24 additions & 3 deletions lua/trouble/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function M:map(key, action)
end, { desc = action.desc, mode = action.mode })
end

---@param opts? {idx?: number, up?:number, down?:number, jump?:boolean}
---@param opts? {idx?: number, up?:number, down?:number, next_file?:boolean, prev_file?:boolean, jump?:boolean}
function M:move(opts)
-- start the moving timer. Will stop any previous timers,
-- so this acts as a debounce.
Expand All @@ -383,13 +383,34 @@ function M:move(opts)
if opts.idx and opts.idx < 0 then
from, to = to, 1
todo = math.abs(todo)
elseif opts.down then
elseif opts.down or opts.next_file then
from = cursor[1] + 1
elseif opts.up then
elseif opts.up or opts.prev_file then
from = cursor[1] - 1
to = 1
end

if opts.next_file or opts.prev_file then
local cur_loc = self:at()
local cur_filename = (cur_loc.item and cur_loc.item.filename)
or (cur_loc.node and cur_loc.node.item and cur_loc.node.item.filename)

if not cur_filename then
return Util.warn("No file found for current item")
end

for row = from, to, opts.next_file and 1 or -1 do
local info = self.renderer:at(row)
if info.node and info.node.group and info.node.item and info.node.item.filename ~= cur_filename then
vim.api.nvim_win_set_cursor(self.win.win, { row, cursor[2] })
return
end
end

local file = opts.next_file and "next" or "previous"
return Util.warn("No " .. file .. " file found")
end

for row = from, to, from > to and -1 or 1 do
local info = self.renderer:at(row)
if info.item and info.first_line then
Expand Down
Loading