sort bookmarks when saving

This commit is contained in:
wekauwau
2024-12-16 14:29:38 +07:00
parent 20ece7e1ef
commit a91fe1cb85

View File

@@ -138,6 +138,28 @@ local save_bookmark = ya.sync(function(state, idx)
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
_save_state(state.bookmarks)
end