feat(knowledge-lookup): restore panel navigation
Persist the active vault folder and selected entry across panel opens, and render the bar widget as an icon only.
This commit is contained in:
@@ -28,6 +28,7 @@ local cutKind: string? = nil
|
||||
local deleteRelative: string? = nil
|
||||
local operationError: string? = nil
|
||||
local searchMode = false
|
||||
local pendingNavigation: { vaultPath: string, currentDir: string, selectedRelative: string }? = nil
|
||||
local loading = false
|
||||
local loadError: string? = nil
|
||||
local render: () -> ()
|
||||
@@ -231,6 +232,54 @@ local function selectedEntry(): any?
|
||||
return visible[selected]
|
||||
end
|
||||
|
||||
local function navigationStatePath(): string?
|
||||
local dataDir = noctalia.pluginDataDir()
|
||||
if type(dataDir) ~= "string" then
|
||||
return nil
|
||||
end
|
||||
return dataDir .. "/navigation-state.json"
|
||||
end
|
||||
|
||||
local function saveNavigation()
|
||||
if vaultPath == "" then
|
||||
return
|
||||
end
|
||||
local path = navigationStatePath()
|
||||
if path == nil then
|
||||
return
|
||||
end
|
||||
local entry = selectedEntry()
|
||||
noctalia.writeFile(path, noctalia.json.encode({
|
||||
vaultPath = vaultPath,
|
||||
currentDir = currentDir,
|
||||
selectedRelative = entry ~= nil and tostring(entry.relative or "") or "",
|
||||
}))
|
||||
end
|
||||
|
||||
local function loadNavigation(): { vaultPath: string, currentDir: string, selectedRelative: string }?
|
||||
local path = navigationStatePath()
|
||||
if path == nil then
|
||||
return nil
|
||||
end
|
||||
local raw = noctalia.readFile(path)
|
||||
if type(raw) ~= "string" then
|
||||
return nil
|
||||
end
|
||||
local saved = noctalia.json.decode(raw)
|
||||
if type(saved) ~= "table"
|
||||
or type(saved.vaultPath) ~= "string"
|
||||
or type(saved.currentDir) ~= "string"
|
||||
or type(saved.selectedRelative) ~= "string"
|
||||
then
|
||||
return nil
|
||||
end
|
||||
return {
|
||||
vaultPath = saved.vaultPath,
|
||||
currentDir = saved.currentDir,
|
||||
selectedRelative = saved.selectedRelative,
|
||||
}
|
||||
end
|
||||
|
||||
local function fullMarkdown(note: any): string
|
||||
local lines = note.lines or {}
|
||||
if #lines == 0 then
|
||||
@@ -245,6 +294,7 @@ local function setSelected(index: number)
|
||||
end
|
||||
selected = math.max(1, math.min(index, #visible))
|
||||
previewTop = 1
|
||||
saveNavigation()
|
||||
render()
|
||||
end
|
||||
|
||||
@@ -452,6 +502,7 @@ local function enterSelected()
|
||||
selected = 1
|
||||
previewTop = 1
|
||||
applyFilter()
|
||||
saveNavigation()
|
||||
render()
|
||||
else
|
||||
enterReader(entry)
|
||||
@@ -473,6 +524,7 @@ local function goParent()
|
||||
end
|
||||
end
|
||||
previewTop = 1
|
||||
saveNavigation()
|
||||
render()
|
||||
end
|
||||
|
||||
@@ -827,7 +879,11 @@ local function completeIndexLoad(selectAfterRefresh: string?, actionAfterRefresh
|
||||
selected = 1
|
||||
applyFilter()
|
||||
end
|
||||
elseif pendingNavigation ~= nil then
|
||||
selectRelative(pendingNavigation.selectedRelative)
|
||||
end
|
||||
pendingNavigation = nil
|
||||
saveNavigation()
|
||||
render()
|
||||
end
|
||||
|
||||
@@ -945,14 +1001,19 @@ validateVault = function(candidate: string?, actionAfterValidation: string?)
|
||||
vaultName = tostring(info.name or "")
|
||||
obsidianVaultId = type(info.vaultId) == "string" and info.vaultId or nil
|
||||
obsidianError = type(info.obsidianError) == "string" and info.obsidianError or nil
|
||||
currentDir = ""
|
||||
selected = 1
|
||||
if actionAfterValidation == "save" then
|
||||
pendingNavigation = nil
|
||||
local dataDir = noctalia.pluginDataDir()
|
||||
if type(dataDir) == "string" then
|
||||
noctalia.writeFile(dataDir .. "/vault-path.txt", vaultPath)
|
||||
end
|
||||
end
|
||||
if pendingNavigation ~= nil and pendingNavigation.vaultPath == vaultPath then
|
||||
currentDir = pendingNavigation.currentDir
|
||||
else
|
||||
currentDir = ""
|
||||
end
|
||||
selected = 1
|
||||
refreshIndex()
|
||||
end, 10000)
|
||||
end
|
||||
@@ -969,11 +1030,12 @@ local function configuredVaultPath(): string
|
||||
end
|
||||
|
||||
function onClose()
|
||||
saveNavigation()
|
||||
end
|
||||
|
||||
function onOpen(_context)
|
||||
-- A plugin runtime can outlive panel-close/open cycles, but user navigation
|
||||
-- must always reopen at the finder root.
|
||||
-- A plugin runtime can outlive panel-close/open cycles; restore navigation
|
||||
-- only when it belongs to the currently configured vault.
|
||||
vaultEditMode = false
|
||||
vaultEditPath = ""
|
||||
searchMode = false
|
||||
@@ -987,6 +1049,7 @@ function onOpen(_context)
|
||||
readerMode = false
|
||||
readerNote = nil
|
||||
query = ""
|
||||
pendingNavigation = loadNavigation()
|
||||
currentDir = ""
|
||||
selected = 1
|
||||
previewTop = 1
|
||||
|
||||
Reference in New Issue
Block a user