Merge pull request #31 from wekauwau/main

Sort bookmarks when saving
This commit is contained in:
Diogo Duarte
2024-12-18 11:16:40 +00:00
committed by GitHub

View File

@@ -138,6 +138,28 @@ local save_bookmark = ya.sync(function(state, idx)
is_parent = file.is_parent, is_parent = file.is_parent,
} }
-- Custom sorting function
table.sort(state.bookmarks, function(a, b)
local key_a, key_b = a.on, b.on
-- Numbers first
if key_a:match("%d") and not key_b:match("%d") then
return true
elseif key_b:match("%d") and not key_a:match("%d") then
return false
end
-- Uppercase before lowercase
if key_a:match("%u") and key_b:match("%l") then
return true
elseif key_b:match("%u") and key_a:match("%l") then
return false
end
-- Regular alphabetical sorting
return key_a < key_b
end)
if state.persist then if state.persist then
_save_state(state.bookmarks) _save_state(state.bookmarks)
end end
@@ -196,8 +218,8 @@ end)
return { return {
entry = function(_, job_or_args) entry = function(_, job_or_args)
-- TODO: DEPRECATE IN Yazi 0.4 -- TODO: DEPRECATE IN Yazi 0.4
-- https://github.com/sxyazi/yazi/pull/1966 -- https://github.com/sxyazi/yazi/pull/1966
local args = job_or_args.args or job_or_args local args = job_or_args.args or job_or_args
local action = args[1] local action = args[1]
if not action then if not action then
return return