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().
Showing the changes to player/lua/console.lua (1 of 1 file). Show all
Unified · Split
| @@ -357,9 +357,11 @@ end · 356 unmodified lines | ||
| 357 | 357 | |
| 358 | 358 | local function fuzzy_find(needle, haystacks) |
| 359 | 359 | 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 | |
| 363 | 365 | for i, value in ipairs(result) do |
| 364 | 366 | result[i] = value[1] |
| 365 | 367 | end |
| @@ -639,14 +641,8 @@ local function handle_edit() · 273 unmodified lines | ||
| 639 | 641 | matches = {} |
| 640 | 642 | selected_match = 1 |
| 641 | 643 | |
| 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] } | |
| 650 | 646 | end |
| 651 | 647 | end |
| 652 | 648 | |
| @@ -902,7 +898,10 @@ local function search_history() · 249 unmodified lines | ||
| 902 | 898 | |
| 903 | 899 | for i = 1, #history do |
| 904 | 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 | 905 | end |
| 907 | 906 | |
| 908 | 907 | update() |