Saving correct folder cursor and path in bookmark

This commit is contained in:
Diogo Duarte
2024-02-09 17:12:08 +00:00
parent 23e5c7a530
commit ce02afdd2e

View File

@@ -30,20 +30,25 @@ local function dump(o)
end end
local function save_bookmark(idx) local function save_bookmark(idx)
ya.err("SAVE BOOKMARK")
if idx == -1 then if idx == -1 then
return return
end end
local folder = Folder:by_kind(Folder.CURRENT)
local key = SUPPORTED_KEYS[idx].on local key = SUPPORTED_KEYS[idx].on
state.bookmarks = state.bookmarks or {} state.bookmarks = state.bookmarks or {}
state.bookmarks[key] = { cursor = 1, path = "ola" } state.bookmarks[key] = { cursor = folder.cursor, path = tostring(folder.cwd) }
end end
local function jump_to_bookmark() local function jump_to_bookmark(bookmark)
ya.err("JUMP TO BOOKMARK") ya.err("JUMP TO BOOKMARK")
state.bookmarks = state.bookmarks or {}
ya.err("BOOKMARK: " .. bookmark)
ya.err("BOOKMARK2: " .. dump(state.bookmarks[bookmark]))
end end
local function next(sync, args) local function next(sync, args)
@@ -57,33 +62,28 @@ return {
return return
end end
ya.err("ARGS: " .. dump(args))
if action == "set" then if action == "set" then
ya.err("SET BOOKMARK")
local key = args[2] local key = args[2]
if not key then if not key then
next(false, { "_set" }) next(false, { "_set" })
else else
ya.err("SET BOOKMARK")
save_bookmark(tonumber(key)) save_bookmark(tonumber(key))
end end
elseif action == "_set" then elseif action == "_set" then
ya.err("_SET")
local key = ya.which({ local key = ya.which({
cands = SUPPORTED_KEYS, cands = SUPPORTED_KEYS,
silent = true, silent = true,
}) })
ya.err(key) if not key then
-- selection was cancelled
return
end
next(true, { "set", key }) next(true, { "set", key })
elseif action == "jump" then elseif action == "jump" then
ya.err("JUMP BOOKMARK") local bookmark = args[2]
if not bookmark then
local key = args[2]
if not key then
-- tried to use ya.sync but was unsuccessful, doing this way for the moment -- tried to use ya.sync but was unsuccessful, doing this way for the moment
if state.bookmarks then if state.bookmarks then
local arguments = { "_jump" } local arguments = { "_jump" }
@@ -93,18 +93,17 @@ return {
next(false, arguments) next(false, arguments)
end end
else else
ya.err("JUMP TO KEY: " .. key) jump_to_bookmark(bookmark)
end end
elseif action == "_jump" then elseif action == "_jump" then
ya.err("_JUMP")
if #args == 1 then if #args == 1 then
-- Should never enter here, but just to be safe
ya.err("No arguments for '_jump'")
return return
end end
local marked_keys = {} local marked_keys = {}
for i = 2, #args, 1 do for i = 2, #args, 1 do
ya.err("I: " .. i)
table.insert(marked_keys, { on = args[i], desc = "Jump to bookmark '" .. args[i] .. "'" }) table.insert(marked_keys, { on = args[i], desc = "Jump to bookmark '" .. args[i] .. "'" })
end end
@@ -112,7 +111,12 @@ return {
cands = marked_keys, cands = marked_keys,
}) })
next(true, { "jump", selected_bookmark }) if not selected_bookmark then
-- selection was cancelled
return
end
next(true, { "jump", marked_keys[selected_bookmark].on })
end end
end, end,
} }