yazi/yazi-plugin/preset/plugins/code.lua
Artyom Artamonov cd7209c040
feat: word wrapping in code previewer (#1159)
Co-authored-by: Lex Moskovski <alex@moskovski.com>
Co-authored-by: sxyazi <sxyazi@gmail.com>
2024-08-26 09:00:09 +08:00

26 lines
604 B
Lua

local M = {}
function M:peek()
local err, bound = ya.preview_code(self)
if bound then
ya.manager_emit("peek", { bound, only_if = self.file.url, upper_bound = true })
elseif err and not err:find("cancelled", 1, true) then
ya.preview_widgets(self, {
ui.Paragraph(self.area, { ui.Line(err):reverse() }),
})
end
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,
})
end
end
return M