Skip to content

BUGFIX: Unstable behavior in the "getPath()" method #795

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

Merged
merged 8 commits into from
Jan 7, 2018

Conversation

lifecrisis
Copy link
Contributor

In addition to a number of style improvements, this PR fixes some unstable behavior for the NERDTreeUI.getPath() method.

To replicate the problem on *nix systems:

  1. Open Vim, then open the NERDTree.
  2. Position cursor on blank line above tree.
  3. Run :echo b:NERDTree.ui.getPath(line('.')) to see that the wrong value is returned (this only works if the working directory is at or beneath the NERDTree root).

This problem doesn't exist on Windows from what I can tell.

@lifecrisis lifecrisis changed the title Fix unstable behavior for the "getPath()" method BUGFIX: Mend unstable behavior for the "getPath()" method Jan 6, 2018
@lifecrisis lifecrisis changed the title BUGFIX: Mend unstable behavior for the "getPath()" method BUGFIX: Unstable behavior in the "getPath()" method Jan 6, 2018
This commit prevents "NERDTreeUI.getPath()" from returning a "Path"
object even when no tree node was selected.  Previously, positioning
your cursor on one of the blank lines above the tree and running...

  :echo g:NERDTreeFileNode.GetSelected()

... could potentially return the path for the current working
directory (your working directory needs to be under the tree root).
This is because the constructor for "Path" objects returns a "Path"
for the current working directory when passed an empty string.  So,
we need to short circuit the "getPath()" function for lines that
cannot possibly be tree nodes.

This solves the problem for "GetSelected()" because that method uses
the "getPath()" method from the "UI" class to do its work.

Note that this bug only presented for me on *nix systems.
@lifecrisis lifecrisis merged commit 183bb53 into preservim:master Jan 7, 2018
@lifecrisis lifecrisis deleted the empty-line branch January 7, 2018 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants