History

console.lua: pre-filter searched commands if the line is filled

If you type something before pressing Ctrl+r, filter the commands containing the typed line. fuzzy_find() is modified to not code a separate case when the line is empty in both handle_edit() or search_history().

Guido Cella committed 2 years ago

Commit 64a0e311 parent 92f052c1 file · +11 −12Browse files

Showing the changes to player/lua/console.lua (1 of 1 file). Show all

Unified · Split

player/lua/console.lua+11−12
@@ -357,9 +357,11 @@ end · 356 unmodified lines
357357
358358 local function fuzzy_find(needle, haystacks)
359359 local result = require 'mp.fzy'.filter(needle, haystacks)
360− table.sort(result, function (i, j)
361− return i[3] > j[3]
362− end)
360+ if line ~= '' then -- Prevent table.sort() from reordering the items.
361+ table.sort(result, function (i, j)
362+ return i[3] > j[3]
363+ end)
364+ end
363365 for i, value in ipairs(result) do
364366 result[i] = value[1]
365367 end
@@ -639,14 +641,8 @@ local function handle_edit() · 273 unmodified lines
639641 matches = {}
640642 selected_match = 1
641643
642− if line == '' then
643− for i, item in ipairs(selectable_items) do
644− matches[i] = { index = i, text = item }
645− end
646− else
647− for i, match in ipairs(fuzzy_find(line, selectable_items)) do
648− matches[i] = { index = match, text = selectable_items[match] }
649− end
644+ for i, match in ipairs(fuzzy_find(line, selectable_items)) do
645+ matches[i] = { index = match, text = selectable_items[match] }
650646 end
651647 end
652648
@@ -902,7 +898,10 @@ local function search_history() · 249 unmodified lines
902898
903899 for i = 1, #history do
904900 selectable_items[i] = history[#history + 1 - i]
905− matches[i] = { index = i, text = history[#history + 1 - i] }
901+ end
902+
903+ for i, match in ipairs(fuzzy_find(line, selectable_items)) do
904+ matches[i] = { index = match, text = selectable_items[match] }
906905 end
907906
908907 update()

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