Not saving cursor anymore

This commit is contained in:
Diogo Duarte
2024-04-26 15:31:37 +01:00
parent c52de13eb0
commit 2d96d05a32

View File

@@ -33,6 +33,11 @@ local _get_real_index = ya.sync(function(state, idx)
return nil return nil
end) end)
local _get_hovered_file = ya.sync(function ()
local folder = Folder:by_kind(Folder.CURRENT)
return folder.window[folder.cursor - folder.offset + 1].url
end)
local _load_state = ya.sync(function(state) local _load_state = ya.sync(function(state)
ps.sub_remote("bookmarks", function(body) ps.sub_remote("bookmarks", function(body)
if not state.bookmarks and body then if not state.bookmarks and body then
@@ -69,18 +74,17 @@ end)
local _save_last_directory = ya.sync(function(state) local _save_last_directory = ya.sync(function(state)
ps.sub("cd", function() ps.sub("cd", function()
local folder = Folder:by_kind(Folder.CURRENT) local file_url = _get_hovered_file()
state.last_dir = state.curr_dir state.last_dir = state.curr_dir
state.curr_dir = { state.curr_dir = {
on = "'", on = "'",
desc = tostring(folder.cwd), desc = tostring(file_url),
cursor = folder.cursor,
} }
end) end)
ps.sub("hover", function() ps.sub("hover", function()
local folder = Folder:by_kind(Folder.CURRENT) local file_url = _get_hovered_file()
state.curr_dir.cursor = folder.cursor state.curr_dir.desc = tostring(file_url)
end) end)
end) end)
@@ -89,7 +93,7 @@ end)
-- ***********************************************/ -- ***********************************************/
local save_bookmark = ya.sync(function(state, idx) local save_bookmark = ya.sync(function(state, idx)
local folder = Folder:by_kind(Folder.CURRENT) local file_url = _get_hovered_file()
state.bookmarks = state.bookmarks or {} state.bookmarks = state.bookmarks or {}
@@ -100,8 +104,7 @@ local save_bookmark = ya.sync(function(state, idx)
state.bookmarks[_idx] = { state.bookmarks[_idx] = {
on = SUPPORTED_KEYS[idx].on, on = SUPPORTED_KEYS[idx].on,
desc = tostring(folder.cwd), desc = tostring(file_url),
cursor = folder.cursor,
} }
if state.persist then if state.persist then
@@ -110,8 +113,8 @@ local save_bookmark = ya.sync(function(state, idx)
if state.notify and state.notify.enable then if state.notify and state.notify.enable then
local message = state.notify.message.new local message = state.notify.message.new
message, _ = message:gsub("<key>", SUPPORTED_KEYS[idx].on) message, _ = message:gsub("<key>", state.bookmarks[_idx].on)
message, _ = message:gsub("<folder>", tostring(folder.cwd)) message, _ = message:gsub("<folder>", state.bookmarks[_idx].desc)
_send_notification(message) _send_notification(message)
end end
end) end)
@@ -185,9 +188,7 @@ return {
end end
if action == "jump" then if action == "jump" then
ya.manager_emit("cd", { bookmarks[selected].desc }) ya.manager_emit("reveal", { bookmarks[selected].desc })
ya.manager_emit("arrow", { -99999999 })
ya.manager_emit("arrow", { bookmarks[selected].cursor })
elseif action == "delete" then elseif action == "delete" then
delete_bookmark(selected) delete_bookmark(selected)
end end