Skip to content

Update directory-movement.lua #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/navigation/directory-movement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function directory_movement.up_dir()
if index == nil then g.state.directory = ""
else g.state.directory = dir:sub(index):reverse() end

if #cache > 0 and cache[#cache]["directory"] == "" then
g.state.directory = ""
end
Comment on lines +42 to +44
Copy link
Owner

@CogentRedTester CogentRedTester Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't strictly fix the issue. This condition assumes that the cache will always reliably show the parent directory, but this is not the case; there are various ways that the cache can be cleared. For example jumping to the directory for the current file will clear the cache, as will using the Ctrl+r rescan keybind. Your previous approach was better, though if you're going to detect if the path contains a protocol scheme you should use the existing API.get_protocol function.

Also if you choose to use the protocol detection method I'd like you to add a new option that disables the behaviour.


--we can make some assumptions about the next directory label when moving up or down
if g.state.directory_label then g.state.directory_label = string.match(g.state.directory_label, "^(.+/)[^/]+/$") end

Expand Down