Skip to content

Commit

Permalink
fix: clamp when seeking a non-zero unit between -1 and 1 (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi authored Oct 5, 2024
1 parent 491f8b8 commit 87b159f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions yazi-plugin/preset/plugins/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ end

function M:seek(units)
local h = cx.active.current.hovered
if h and h.url == self.file.url then
local step = math.floor(units * self.area.h / 10)
ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
})
if not h or h.url ~= self.file.url then
return
end

local step = math.floor(units * self.area.h / 10)
step = step == 0 and ya.clamp(-1, units, 1) or step

ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
})
end

return M

0 comments on commit 87b159f

Please sign in to comment.