Skip to content

Commit

Permalink
fix: buffer cycling small errors (#234)
Browse files Browse the repository at this point in the history
* fix: do not cycle buffers if there are no visible buffers

* fix: ignore error when no target found
  • Loading branch information
mikavilpas authored Jul 21, 2024
1 parent bf57797 commit a43465e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lua/yazi/keybinding_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ function YaziOpenerActions.cycle_open_buffers(context)
) or context.input_path
local visible_buffers = utils.get_visible_open_buffers()

if #visible_buffers == 0 then
Log:debug(
string.format(
'No visible buffers found for path: "%s"',
context.input_path
)
)
return
end

for i, buffer in ipairs(visible_buffers) do
if
buffer.renameable_buffer:matches_exactly(current_cycle_position.filename)
Expand All @@ -87,15 +97,16 @@ function YaziOpenerActions.cycle_open_buffers(context)
return b.renameable_buffer.path.filename
~= current_cycle_position.filename
end)
assert(
next_buffer,
vim.inspect({
'Could not find next buffer',
#visible_buffers,
i,
next,
})
)

if not next_buffer then
Log:debug(
string.format(
'Could not find next buffer for path: "%s", probably only one is open.',
context.input_path
)
)
return
end

local directory =
vim.fn.fnamemodify(next_buffer.renameable_buffer.path.filename, ':h')
Expand Down

0 comments on commit a43465e

Please sign in to comment.