Previously closing NERDTree while two windows were showing the same
buffer would focus the first window, which was not necessarily the
previously active one.
Instead of obtaining the buffer ID of the previous buffer and
mapping that to the window ID (which is a 1:n mapping) we obtain the
unique window ID and focus the right window after closing NERDTree.
win_getid() and win_gotoid() are available from VIM 7.4.1557 but the
old behavior is used as a fallback if the two functions are not
available.
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.
The small change here reverts an attempted bugfix from #785. That
change resulted in the unintended side-effect of closing other
children of the root whenever ":NERDTreeFind" was invoked. This was
disruptive (as reported in #793), so a new method must be found to
solve the problem of ":NERDTreeFind" not opening newly created
files.
Fixes#793.
Here, a more accurate method of determining whether or not to show
hidden files is used. A new method, "isHiddenUnder()" is defined
for "Path" objects. This method is then used to set the flag for
hidden files in the ":NERDTreeFind" command. Note that this
function is likely to be useful elsewhere.
Fixes#189.
In certain cases, ":NERDTreeFind" would fail to reveal files that
were created/written after the current tab's NERDTree had been
initialized. This pull request repairs that problem.
If a file does not exist for the current buffer, this function
should fail with a clear warning message.
Here, I improved the messages that this function prints so that it
fails gracefully when no path can be determined in the calling
context.
The ":NERDTreeFind" command calls the "reveal()" method on the
NERDTree root node. The "reveal()" method would, in turn, call the
node's "open()" method. Since the "open()" method would only
initialize the child nodes of the root (i.e., read them from disk)
when the list of child nodes was empty, new paths would not be
included in the list.
This commit will result in the refreshing of the child node list
whenever "reveal()" is called on a directory node (unless it is the
first time the node is being opened... the most efficient option).
The result is that ":NERDTreeFind" will discover newly created paths
that exist on disk but are not cached in the NERDTree.
A stray debugging message is also removed.
Fixes issue #779.
Function-local variables, instead of script-local variables, should
be used here. In addition, "empty()" is a better choice for testing
for the absence of an argument. Finally, the use of "else" is
removed.
The docstring is also updated to include the new argument.
I contend that we should use confirm() whenever possible. It makes
the code cleaner and uses a builtin feature rather than a custom
one. Doing it the "Vim way" is always preferable in my mind.
The "o" mapping, which toggles directory nodes open/closed, allowed
the user to close the tree root. This was not consistent with the
"x" mapping which stops the user from doing this. This applies to
a double-click on the root node as well.
It should be noted that, if the root node is somehow closed, "o" and
double click can still re-open the tree, even with this change. In
other words, I was careful.
Previously, pressing "x" on the tree root would result in
unpredictable behavior. The user would either an receive an error
message or the parent of the tree root (which is not visible) would
be closed. This commit repairs this problem.
In addition, some code duplication was removed.