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
357 357
358local function fuzzy_find(needle, haystacks)358local function fuzzy_find(needle, haystacks)
359 local result = require 'mp.fzy'.filter(needle, haystacks)359 local result = require 'mp.fzy'.filter(needle, haystacks)
360 table.sort(result, function (i, j)360 if line ~= '' then -- Prevent table.sort() from reordering the items.
361 return i[3] > j[3]361 table.sort(result, function (i, j)
362 end)362 return i[3] > j[3]
363 end)
364 end
363 for i, value in ipairs(result) do365 for i, value in ipairs(result) do
364 result[i] = value[1]366 result[i] = value[1]
365 end367 end
@@ -639,14 +641,8 @@ local function handle_edit() · 273 unmodified lines
639 matches = {}641 matches = {}
640 selected_match = 1642 selected_match = 1
641 643
642 if line == '' then644 for i, match in ipairs(fuzzy_find(line, selectable_items)) do
643 for i, item in ipairs(selectable_items) do645 matches[i] = { index = match, text = selectable_items[match] }
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
650 end646 end
651 end647 end
652 648
@@ -902,7 +898,10 @@ local function search_history() · 249 unmodified lines
902 898
903 for i = 1, #history do899 for i = 1, #history do
904 selectable_items[i] = history[#history + 1 - i]900 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] }
906 end905 end
907 906
908 update()907 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