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.
This commit is contained in:
14
init.lua
14
init.lua
@@ -37,14 +37,14 @@ local _get_bookmark_file = ya.sync(function(state)
|
|||||||
local folder = cx.active.current
|
local folder = cx.active.current
|
||||||
|
|
||||||
if state.file_pick_mode == "parent" or not folder.hovered then
|
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
|
end
|
||||||
return { url = folder.hovered.url, is_cwd = false }
|
return { url = folder.hovered.url, is_parent = false }
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _generate_description = ya.sync(function(state, file)
|
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 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)
|
return tostring(file.url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -106,6 +106,7 @@ local _save_last_directory = ya.sync(function(state, persist)
|
|||||||
on = "'",
|
on = "'",
|
||||||
desc = _generate_description(file),
|
desc = _generate_description(file),
|
||||||
path = tostring(file.url),
|
path = tostring(file.url),
|
||||||
|
is_parent = file.is_parent,
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -134,6 +135,7 @@ local save_bookmark = ya.sync(function(state, idx)
|
|||||||
on = SUPPORTED_KEYS[idx].on,
|
on = SUPPORTED_KEYS[idx].on,
|
||||||
desc = _generate_description(file),
|
desc = _generate_description(file),
|
||||||
path = tostring(file.url),
|
path = tostring(file.url),
|
||||||
|
is_parent = file.is_parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.persist then
|
if state.persist then
|
||||||
@@ -217,7 +219,11 @@ return {
|
|||||||
end
|
end
|
||||||
|
|
||||||
if action == "jump" then
|
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
|
elseif action == "delete" then
|
||||||
delete_bookmark(selected)
|
delete_bookmark(selected)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user