Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions yazi-plugin/preset/components/folder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down