From 6769310fa2fc0ca6ce0a35de0c3eb7986af538fe Mon Sep 17 00:00:00 2001 From: nralbrecht Date: Wed, 28 Aug 2024 17:34:29 +0200 Subject: [PATCH] Change to directory if the parent is stored When storing a hovered file as bookmark it makes sense to use the reveal command to move to it. When storing the parent directory however, one has to cd to it. Otherwise the parent directory is opened and the stored directory is only focused. --- init.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 2e670d0..03a50c5 100644 --- a/init.lua +++ b/init.lua @@ -37,14 +37,14 @@ local _get_bookmark_file = ya.sync(function(state) local folder = cx.active.current if state.file_pick_mode == "parent" or not folder.hovered then - return { url = folder.cwd, is_cwd = true } + return { url = folder.cwd, is_parent = true } end - return { url = folder.hovered.url, is_cwd = false } + return { url = folder.hovered.url, is_parent = false } end) local _generate_description = ya.sync(function(state, file) -- if this is true, we don't have information about the folder, so just return the folder url - if file.is_cwd then + if file.is_parent then return tostring(file.url) end @@ -106,6 +106,7 @@ local _save_last_directory = ya.sync(function(state, persist) on = "'", desc = _generate_description(file), path = tostring(file.url), + is_parent = file.is_parent, } end) @@ -134,6 +135,7 @@ local save_bookmark = ya.sync(function(state, idx) on = SUPPORTED_KEYS[idx].on, desc = _generate_description(file), path = tostring(file.url), + is_parent = file.is_parent, } if state.persist then @@ -217,7 +219,11 @@ return { end if action == "jump" then - ya.manager_emit("reveal", { bookmarks[selected].path }) + if bookmarks[selected].is_parent then + ya.manager_emit("cd", { bookmarks[selected].path }) + else + ya.manager_emit("reveal", { bookmarks[selected].path }) + end elseif action == "delete" then delete_bookmark(selected) end