Skip to content

Commit

Permalink
fix(mappings): attempt to get next buffer when using history fallback
Browse files Browse the repository at this point in the history
Problem: when there is no next/prev buffer (a buffer is unlisted), the mappings will switch to the
previous buffer in the history, regardless of the step provided.
Solution: attempt to find a buffer relative to the previous buffer
  • Loading branch information
willothy committed Oct 4, 2023
1 parent 6c8f3dc commit 2bf44ee
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/cokeline/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ local by_step = function(goal, step)
target_buf = state.valid_buffers[target_idx]
elseif goal == "focus" and config.history.enabled then
target_buf = require("cokeline.history"):last()
if step < -1 then
-- The result of history:last() is the index -1,
-- so we need to step back one more.
step = step + 1
end
if target_buf and step ~= 0 then
local step_buf = state.valid_buffers[target_buf._valid_index + step]
if step_buf then
target_buf = step_buf
end
end
else
return
end
Expand Down

0 comments on commit 2bf44ee

Please sign in to comment.