History

console.lua: preserve the order of items with equal score

table.sort() is unstable, meaning that it randomly reorders items with the same score, so currently fuzzy_find() checks if the line is empty to not change the original order of the unsorted items. But actually filled lines have the same problem: e.g. searching foo with filenames like foo_{1..99}, they are returned in random order. To fix this sort by score only when 2 items have different score, else sort by the original position.

Guido Cella committed 1 year ago

Commit 8ae3bee1 parent 7ded2901 file · +6 −4Browse files

Unified · Split

player/lua/console.lua+6−4
@@ -410,11 +410,13 @@ end · 409 unmodified lines
410410
411411 local function fuzzy_find(needle, haystacks, case_sensitive)
412412 local result = require 'mp.fzy'.filter(needle, haystacks, case_sensitive)
413− if line ~= '' then -- Prevent table.sort() from reordering the items.
414− table.sort(result, function (i, j)
413+ table.sort(result, function (i, j)
414+ if i[3] ~= j[3] then
415415 return i[3] > j[3]
416− end)
417− end
416+ end
417+
418+ return i[1] < j[1]
419+ end)
418420 for i, value in ipairs(result) do
419421 result[i] = value[1]
420422 end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t