feat: add a new Folder:icon() API to make it easier for users to extend icons (#301)

This commit is contained in:
三咲雅 · Misaki Masa 2023-10-23 12:36:54 +08:00 committed by GitHub
parent 6d3457dde0
commit c9178d4ab3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,8 @@ function Folder:by_kind(kind)
end
end
function Folder:icon(file) return ui.Span(" " .. file:icon() .. " ") end
function Folder:highlighted_name(file)
-- Complete prefix when searching across directories
local prefix = file:prefix() or ""
@ -115,7 +117,7 @@ function Folder:parent(area)
local items = {}
for _, f in ipairs(folder.window) do
local item = ui.ListItem(" " .. f:icon() .. " " .. f.name .. " ")
local item = ui.ListItem(ui.Line { self:icon(f), ui.Span(f.name) })
if f:is_hovered() then
item = item:style(THEME.manager.hovered)
else
@ -135,7 +137,7 @@ function Folder:current(area)
local name = self:highlighted_name(f)
-- Highlight hovered file
local item = ui.ListItem(ui.Line { ui.Span(" " .. f:icon() .. " "), table.unpack(name) })
local item = ui.ListItem(ui.Line { self:icon(f), table.unpack(name) })
if f:is_hovered() then
item = item:style(THEME.manager.hovered)
else
@ -162,7 +164,7 @@ function Folder:preview(area)
local items = {}
for _, f in ipairs(folder.window) do
local item = ui.ListItem(" " .. f:icon() .. " " .. f.name .. " ")
local item = ui.ListItem(ui.Line { self:icon(f), ui.Span(f.name) })
if f:is_hovered() then
item = item:style(THEME.manager.preview_hovered)
else