Closes https://github.com/yazi-rs/plugins/pull/116 Closes https://github.com/yazi-rs/plugins/pull/118 Closes https://github.com/yazi-rs/plugins/pull/121
50 lines
914 B
Lua
50 lines
914 B
Lua
--- @since 25.5.28
|
|
|
|
local hovered = ya.sync(function()
|
|
local h = cx.active.current.hovered
|
|
if not h then
|
|
return {}
|
|
end
|
|
|
|
return {
|
|
url = h.url,
|
|
is_dir = h.cha.is_dir,
|
|
unique = #cx.active.current.files == 1,
|
|
}
|
|
end)
|
|
|
|
local function prompt()
|
|
return ya.input {
|
|
title = "Smart filter:",
|
|
position = { "center", w = 50 },
|
|
realtime = true,
|
|
debounce = 0.1,
|
|
}
|
|
end
|
|
|
|
local function entry()
|
|
local input = prompt()
|
|
|
|
while true do
|
|
local value, event = input:recv()
|
|
if event ~= 1 and event ~= 3 then
|
|
ya.emit("escape", { filter = true })
|
|
break
|
|
end
|
|
|
|
ya.emit("filter_do", { value, smart = true })
|
|
|
|
local h = hovered()
|
|
if h.unique and h.is_dir then
|
|
ya.emit("escape", { filter = true })
|
|
ya.emit("enter", {})
|
|
input = prompt()
|
|
elseif event == 1 then
|
|
ya.emit("escape", { filter = true })
|
|
ya.emit(h.is_dir and "enter" or "open", { h.url })
|
|
end
|
|
end
|
|
end
|
|
|
|
return { entry = entry }
|