Skip to content

Commit

Permalink
refactor!: don't delete buffer when falling back to history
Browse files Browse the repository at this point in the history
  • Loading branch information
willothy committed Oct 4, 2023
1 parent 7cb318f commit 84dded2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lua/cokeline/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local by_index = function(goal, index)
end
end

---@param goal '"switch"' | '"focus"' |'"close"' | fun(buf: Buffer)
---@param goal '"switch"' | '"focus"' |'"close"' | fun(buf: Buffer, did_fallback: boolean)
---@param step -1 | 1
local by_step = function(goal, step)
local config = lazy("cokeline.config")
Expand All @@ -53,6 +53,7 @@ local by_step = function(goal, step)

local target_buf
local target_idx
local did_fallback = false
if focused_buffer then
target_idx = focused_buffer._valid_index + step
if target_idx < 1 or target_idx > #state.valid_buffers then
Expand All @@ -63,6 +64,7 @@ local by_step = function(goal, step)
end
target_buf = state.valid_buffers[target_idx]
elseif goal == "focus" and config.history.enabled then
did_fallback = true
target_buf = require("cokeline.history"):last()
if step < -1 then
-- The result of history:last() is the index -1,
Expand All @@ -84,10 +86,10 @@ local by_step = function(goal, step)
buffers.move_buffer(focused_buffer, target_idx)
elseif goal == "focus" then
target_buf:focus()
elseif goal == "close" then
elseif goal == "close" and not did_fallback then
target_buf:delete()
elseif type(goal) == "function" then
goal(target_buf)
goal(target_buf, did_fallback)
end
end
end
Expand Down

0 comments on commit 84dded2

Please sign in to comment.