Improve alphabetical sorting

This commit is contained in:
Jean-Patrick Guerrero 2022-07-03 19:39:07 +02:00
parent 222e04d2c4
commit 5a14116b69
2 changed files with 6 additions and 5 deletions

View File

@ -344,7 +344,7 @@ end
i3.add_sorting_method("alphabetical", {
description = S"Sort items by name (A-Z)",
func = function(list, data)
sorter(list, data.reverse_sorting, 1)
sorter(list, data, 1)
return list
end
})
@ -352,7 +352,7 @@ i3.add_sorting_method("alphabetical", {
i3.add_sorting_method("numerical", {
description = S"Sort items by number of items per stack",
func = function(list, data)
sorter(list, data.reverse_sorting, 2)
sorter(list, data, 2)
return list
end,
})

View File

@ -482,15 +482,16 @@ local function get_sorting_idx(name)
return idx
end
local function sorter(inv, reverse, mode)
local function sorter(inv, data, mode)
sort(inv, function(a, b)
if mode == 1 then
a, b = a:get_name(), b:get_name()
a = translate(data.lang_code, a:get_short_description())
b = translate(data.lang_code, b:get_short_description())
else
a, b = a:get_count(), b:get_count()
end
if reverse then
if data.reverse_sorting then
return a > b
end