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 deleteRelative: string? = nil
|
||||||
local operationError: string? = nil
|
local operationError: string? = nil
|
||||||
local searchMode = false
|
local searchMode = false
|
||||||
|
local pendingNavigation: { vaultPath: string, currentDir: string, selectedRelative: string }? = nil
|
||||||
local loading = false
|
local loading = false
|
||||||
local loadError: string? = nil
|
local loadError: string? = nil
|
||||||
local render: () -> ()
|
local render: () -> ()
|
||||||
@@ -231,6 +232,54 @@ local function selectedEntry(): any?
|
|||||||
return visible[selected]
|
return visible[selected]
|
||||||
end
|
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 function fullMarkdown(note: any): string
|
||||||
local lines = note.lines or {}
|
local lines = note.lines or {}
|
||||||
if #lines == 0 then
|
if #lines == 0 then
|
||||||
@@ -245,6 +294,7 @@ local function setSelected(index: number)
|
|||||||
end
|
end
|
||||||
selected = math.max(1, math.min(index, #visible))
|
selected = math.max(1, math.min(index, #visible))
|
||||||
previewTop = 1
|
previewTop = 1
|
||||||
|
saveNavigation()
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -452,6 +502,7 @@ local function enterSelected()
|
|||||||
selected = 1
|
selected = 1
|
||||||
previewTop = 1
|
previewTop = 1
|
||||||
applyFilter()
|
applyFilter()
|
||||||
|
saveNavigation()
|
||||||
render()
|
render()
|
||||||
else
|
else
|
||||||
enterReader(entry)
|
enterReader(entry)
|
||||||
@@ -473,6 +524,7 @@ local function goParent()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
previewTop = 1
|
previewTop = 1
|
||||||
|
saveNavigation()
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -827,7 +879,11 @@ local function completeIndexLoad(selectAfterRefresh: string?, actionAfterRefresh
|
|||||||
selected = 1
|
selected = 1
|
||||||
applyFilter()
|
applyFilter()
|
||||||
end
|
end
|
||||||
|
elseif pendingNavigation ~= nil then
|
||||||
|
selectRelative(pendingNavigation.selectedRelative)
|
||||||
end
|
end
|
||||||
|
pendingNavigation = nil
|
||||||
|
saveNavigation()
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -945,14 +1001,19 @@ validateVault = function(candidate: string?, actionAfterValidation: string?)
|
|||||||
vaultName = tostring(info.name or "")
|
vaultName = tostring(info.name or "")
|
||||||
obsidianVaultId = type(info.vaultId) == "string" and info.vaultId or nil
|
obsidianVaultId = type(info.vaultId) == "string" and info.vaultId or nil
|
||||||
obsidianError = type(info.obsidianError) == "string" and info.obsidianError or nil
|
obsidianError = type(info.obsidianError) == "string" and info.obsidianError or nil
|
||||||
currentDir = ""
|
|
||||||
selected = 1
|
|
||||||
if actionAfterValidation == "save" then
|
if actionAfterValidation == "save" then
|
||||||
|
pendingNavigation = nil
|
||||||
local dataDir = noctalia.pluginDataDir()
|
local dataDir = noctalia.pluginDataDir()
|
||||||
if type(dataDir) == "string" then
|
if type(dataDir) == "string" then
|
||||||
noctalia.writeFile(dataDir .. "/vault-path.txt", vaultPath)
|
noctalia.writeFile(dataDir .. "/vault-path.txt", vaultPath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if pendingNavigation ~= nil and pendingNavigation.vaultPath == vaultPath then
|
||||||
|
currentDir = pendingNavigation.currentDir
|
||||||
|
else
|
||||||
|
currentDir = ""
|
||||||
|
end
|
||||||
|
selected = 1
|
||||||
refreshIndex()
|
refreshIndex()
|
||||||
end, 10000)
|
end, 10000)
|
||||||
end
|
end
|
||||||
@@ -969,11 +1030,12 @@ local function configuredVaultPath(): string
|
|||||||
end
|
end
|
||||||
|
|
||||||
function onClose()
|
function onClose()
|
||||||
|
saveNavigation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function onOpen(_context)
|
function onOpen(_context)
|
||||||
-- A plugin runtime can outlive panel-close/open cycles, but user navigation
|
-- A plugin runtime can outlive panel-close/open cycles; restore navigation
|
||||||
-- must always reopen at the finder root.
|
-- only when it belongs to the currently configured vault.
|
||||||
vaultEditMode = false
|
vaultEditMode = false
|
||||||
vaultEditPath = ""
|
vaultEditPath = ""
|
||||||
searchMode = false
|
searchMode = false
|
||||||
@@ -987,6 +1049,7 @@ function onOpen(_context)
|
|||||||
readerMode = false
|
readerMode = false
|
||||||
readerNote = nil
|
readerNote = nil
|
||||||
query = ""
|
query = ""
|
||||||
|
pendingNavigation = loadNavigation()
|
||||||
currentDir = ""
|
currentDir = ""
|
||||||
selected = 1
|
selected = 1
|
||||||
previewTop = 1
|
previewTop = 1
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local PANEL_ID = "alex/knowledge-lookup:panel"
|
|||||||
|
|
||||||
function update()
|
function update()
|
||||||
barWidget.setGlyph("book-2")
|
barWidget.setGlyph("book-2")
|
||||||
barWidget.setText("KB")
|
barWidget.setText("")
|
||||||
barWidget.setTooltip("Knowledge lookup · Super+N")
|
barWidget.setTooltip("Knowledge lookup · Super+N")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user