fix: clamp when seeking a non-zero unit between -1 and 1 (#1736)

This commit is contained in:
三咲雅 · Misaki Masa 2024-10-05 22:32:18 +08:00 committed by GitHub
parent 491f8b8fb1
commit 87b159fb9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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