mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 03:52:22 +02:00
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().
This commit is contained in:
parent
92f052c14e
commit
64a0e31aa9
@ -357,9 +357,11 @@ end
|
|||||||
|
|
||||||
local function fuzzy_find(needle, haystacks)
|
local function fuzzy_find(needle, haystacks)
|
||||||
local result = require 'mp.fzy'.filter(needle, haystacks)
|
local result = require 'mp.fzy'.filter(needle, haystacks)
|
||||||
table.sort(result, function (i, j)
|
if line ~= '' then -- Prevent table.sort() from reordering the items.
|
||||||
return i[3] > j[3]
|
table.sort(result, function (i, j)
|
||||||
end)
|
return i[3] > j[3]
|
||||||
|
end)
|
||||||
|
end
|
||||||
for i, value in ipairs(result) do
|
for i, value in ipairs(result) do
|
||||||
result[i] = value[1]
|
result[i] = value[1]
|
||||||
end
|
end
|
||||||
@ -639,14 +641,8 @@ local function handle_edit()
|
|||||||
matches = {}
|
matches = {}
|
||||||
selected_match = 1
|
selected_match = 1
|
||||||
|
|
||||||
if line == '' then
|
for i, match in ipairs(fuzzy_find(line, selectable_items)) do
|
||||||
for i, item in ipairs(selectable_items) do
|
matches[i] = { index = match, text = selectable_items[match] }
|
||||||
matches[i] = { index = i, text = item }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i, match in ipairs(fuzzy_find(line, selectable_items)) do
|
|
||||||
matches[i] = { index = match, text = selectable_items[match] }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -902,7 +898,10 @@ local function search_history()
|
|||||||
|
|
||||||
for i = 1, #history do
|
for i = 1, #history do
|
||||||
selectable_items[i] = history[#history + 1 - i]
|
selectable_items[i] = history[#history + 1 - i]
|
||||||
matches[i] = { index = i, text = history[#history + 1 - i] }
|
end
|
||||||
|
|
||||||
|
for i, match in ipairs(fuzzy_find(line, selectable_items)) do
|
||||||
|
matches[i] = { index = match, text = selectable_items[match] }
|
||||||
end
|
end
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
Loading…
Reference in New Issue
Block a user