2023-12-26 14:48:33 +03:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M:peek()
|
|
|
|
local folder = Folder:by_kind(Folder.PREVIEW)
|
2024-02-15 15:20:28 +03:00
|
|
|
if not folder or folder.cwd ~= self.file.url then
|
2023-12-26 14:48:33 +03:00
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local bound = math.max(0, #folder.files - self.area.h)
|
|
|
|
if self.skip > bound then
|
|
|
|
ya.manager_emit("peek", { tostring(bound), only_if = tostring(self.file.url), upper_bound = "" })
|
|
|
|
end
|
|
|
|
|
2024-02-15 15:20:28 +03:00
|
|
|
local items, markers = {}, {}
|
|
|
|
for i, f in ipairs(folder.window) do
|
|
|
|
-- Highlight hovered file
|
2023-12-26 14:48:33 +03:00
|
|
|
local item = ui.ListItem(ui.Line { Folder:icon(f), ui.Span(f.name) })
|
|
|
|
if f:is_hovered() then
|
|
|
|
item = item:style(THEME.manager.preview_hovered)
|
|
|
|
else
|
|
|
|
item = item:style(f:style())
|
|
|
|
end
|
|
|
|
items[#items + 1] = item
|
2024-02-15 15:20:28 +03:00
|
|
|
|
|
|
|
-- Mark yanked/selected files
|
|
|
|
local yanked = f:is_yanked()
|
|
|
|
if yanked ~= 0 then
|
|
|
|
markers[#markers + 1] = { i, yanked }
|
|
|
|
elseif f:is_selected() then
|
|
|
|
markers[#markers + 1] = { i, 3 }
|
|
|
|
end
|
2023-12-26 14:48:33 +03:00
|
|
|
end
|
2024-02-15 15:20:28 +03:00
|
|
|
|
|
|
|
ya.preview_widgets(
|
|
|
|
self,
|
|
|
|
ya.flat {
|
|
|
|
ui.List(self.area, items),
|
|
|
|
Folder:markers(self.area, markers),
|
|
|
|
}
|
|
|
|
)
|
2023-12-26 14:48:33 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function M:seek(units)
|
|
|
|
local folder = Folder:by_kind(Folder.PREVIEW)
|
|
|
|
if folder and folder.cwd == self.file.url then
|
|
|
|
local step = math.floor(units * self.area.h / 10)
|
|
|
|
local bound = math.max(0, #folder.files - self.area.h)
|
|
|
|
ya.manager_emit("peek", {
|
|
|
|
tostring(ya.clamp(0, cx.active.preview.skip + step, bound)),
|
|
|
|
only_if = tostring(self.file.url),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|