-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
* fix duplicated slash in s:Path.isUnder() (on windows OS) #1122
Conversation
…irectory on drive Path.str() return path with [back]slash)
…rect comparison of paths without transformations
The str() function returns "C:\" on the root folder and "C:\temp" on non-root folders, one with and one without a trailing backslash. This inconsistency needs to be handled so the stridx() function will work correctly.
This commit handles an edge case that can be triggered with these commands: :cd /home/me :e /foobar.txt (an existing file) :NERDTreeFind What happened was the root directory name '/' was being Resolved(), and the trailing (and only) slash was being removed. The NERDTree was then created in the current working directory, instead of the root directory. :NERDTreeFind then wasn't able to find foobar.txt, and printed an error.
@Eugenij-W , why did you change your mind on the first commit, the one using |
the first version is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the succinctness of the substitute()
function, but I'm OK with either approach. Do you have any metrics to back up your claim?
I tested this PR on my MacOS, and discovered this edge case. It happens only when NERDTree hasn't already been created.
:cd /home/me
:e /foobar.txt
:NERDTreeFind
I tracked it down to the lib/nerdtree/creator.vim
file, and uploaded the fix in #1124. Copy that change into your PR, so it's all in one.
Thanks for tracking this down.
lib/nerdtree/path.vim
Outdated
let this = self.str() | ||
let that = a:path.str() | ||
return stridx(that, this) ==# 0 | ||
return a:path.isUnder(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the variable names lead to some ambiguity. Change path
to child
. This function isn't used within NERDTree, but we'll leave it, in case any other plugins use it.
lib/nerdtree/path.vim
Outdated
let this = self.str() | ||
let that = a:path.str() | ||
return stridx(this, that . s:Path.Slash()) ==# 0 | ||
if nerdtree#runningWindows() && a:path.drive !=# self.drive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ambiguity issue here. Rename a:path
to a:parent
, and that_count
to parent_count
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, glad to help.
Fix exception in NERDTreeFind.
On windows OS and if the file is located in the root directory of the disk, TreeDirNode.reveal() trow exception because Path.isUnder() duplicate slash on root drive paths (look like "c://").
Description of Changes
using substitute() to add a slash.Rewrite NERDTreePath.isUnder() and NERDTreePath.isAncestor() for direct comparison of paths without transformations.
New Version Info
Author's Instructions
MAJOR.MINOR.PATCH
version number. Increment the:MAJOR
version when you make incompatible API changesMINOR
version when you add functionality in a backwards-compatible mannerPATCH
version when you make backwards-compatible bug fixesCollaborator's Instructions
git tag -a 3.1.4 -m "v3.1.4" && git push origin --tags