Settings shortcut in the panel header, middle-elided paths, right-click copy, and a real indexed-file count. Co-authored-by: nightwatch75 <nightwatch75@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
71 lines
2.0 KiB
Luau
71 lines
2.0 KiB
Luau
--!nonstrict
|
|
-- file-search — bar widget that toggles the fuzzy search panel.
|
|
--
|
|
-- The panel (panel.luau) publishes its open state on the shared
|
|
-- "file_search_open" state key; the glyph lights up while it is open.
|
|
--
|
|
-- Click mapping:
|
|
-- Left click — open/close the search panel
|
|
-- Right click — open the search folder in the file manager
|
|
--
|
|
-- Middle click is deliberately not handled: every bar widget carries a built-in
|
|
-- `middle = settings-open-widget` binding, and a bound gesture is masked off the
|
|
-- widget's own input area, so an onMiddleClick here would never be called. The
|
|
-- manifest could reclaim it with `[widget.actions] middle = "none"` (plugin API
|
|
-- 14) — this plugin stays at the upstream behaviour instead.
|
|
|
|
local PANEL_ID = "nightwatch75/file-search:panel"
|
|
|
|
local open = false
|
|
|
|
local function shellQuote(value)
|
|
return "'" .. value:gsub("'", "'\\''") .. "'"
|
|
end
|
|
|
|
local function searchRoot()
|
|
local dir = noctalia.getConfig("search_folder")
|
|
if dir == nil or dir == "" then
|
|
dir = noctalia.getenv("HOME") or "/tmp"
|
|
else
|
|
dir = noctalia.expandPath(dir)
|
|
end
|
|
dir = dir:gsub("/+$", "")
|
|
if dir == "" then
|
|
dir = "/"
|
|
end
|
|
return dir
|
|
end
|
|
|
|
local function render()
|
|
barWidget.setGlyph(noctalia.getConfig("glyph"))
|
|
local root = searchRoot()
|
|
if open then
|
|
barWidget.setGlyphColor("primary")
|
|
barWidget.setTooltip(noctalia.tr("tooltip_open", { path = root }))
|
|
else
|
|
barWidget.setGlyphColor("on_surface")
|
|
barWidget.setTooltip(noctalia.tr("tooltip_closed", { path = root }))
|
|
end
|
|
end
|
|
|
|
noctalia.state.watch("file_search_open", function(value)
|
|
open = value == true
|
|
render()
|
|
end)
|
|
|
|
-- Periodic re-render keeps the glyph and tooltip in sync with settings changes.
|
|
function update()
|
|
render()
|
|
end
|
|
|
|
function onClick()
|
|
noctalia.togglePanel(PANEL_ID)
|
|
end
|
|
|
|
function onRightClick()
|
|
noctalia.runAsync("xdg-open " .. shellQuote(searchRoot()) .. " >/dev/null 2>&1")
|
|
end
|
|
|
|
noctalia.setUpdateInterval(1000)
|
|
render()
|