sort bookmarks when saving
This commit is contained in:
22
init.lua
22
init.lua
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user