Skip to content

Commit

Permalink
Update init.lua
Browse files Browse the repository at this point in the history
sort parcel list, but add new ones at the top, till the next time it is reloaded.
  • Loading branch information
jandegithub committed Jan 27, 2024
1 parent 61e15b6 commit ad38ea3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion init.lua
Expand Up @@ -58,6 +58,24 @@ local function LoadSettings()
SaveSettings()
else
settings = config()
local function getKeysSortedByValue(tbl, sortFunction)
local keys = {}
local newtbl = {}
for key in pairs(tbl) do
table.insert(keys, key)
end

table.sort(keys, function(a, b)
return sortFunction(tbl[a], tbl[b])
end)

for _, key in ipairs(keys) do
table.insert(newtbl, tbl[key])
end
return newtbl
end

settings.History = getKeysSortedByValue(settings.History, function(a, b) return a < b end)
end
end

Expand Down Expand Up @@ -119,7 +137,7 @@ local function doParceling()

settings.History = settings.History or {}
if not has_value(settings.History, parcelTarget) then
table.insert(settings.History, parcelTarget)
table.insert(settings.History, 1, parcelTarget)
SaveSettings()
end

Expand Down

0 comments on commit ad38ea3

Please sign in to comment.