This commit refactors the "nerdtree#ui_glue#UpDir()" function to fix
a bug in the behavior of the 'u' mapping. To reproduce the bug:
1. Open a bookmarked directory with 'o'
2. Press 'u' twice, observing normal behavior
3. Open the same bookmark again with 'o'
4. Press 'u' again, observe the new root is closed
The reason for this bug is that the parent node already existed and
was closed by the second 'u' press in step two above.
This commit fixes this bug by being careful to always open the new
root and transplant the child node properly. Also, the internals of
the function in question were refactored to make use of valuable
NERDTree functions that ultimately help to reduce the amount of code
needed for this operation.
The definitions for certain bookmark mappings reference callbacks
that don't actually support operation on bookmarks. Furthermore,
the mappings that are defined are not documented anywhere. Removing
them seems reasonable since they serve no real purpose.
When a path is rendered in the Bookmarks area or as the header line of the
tree, it is truncated if there is no enough space for it. But if a path
contains multi-byte characters, it should be truncated by characters, not
bytes, otherwise the path may be truncated between the bytes of a
multi-byte character. To deal with multi-byte characters, use
strdisplaywidth() instead of len() to get the number of display cells, and
use strcharpart() instead of strpart() to truncate a path.
Previously, exiting the NERDTree menu with "Ctrl-C" or "Esc" would
leave the last line of the menu visible. We can avoid this by
redrawing the screen when the menu is aborted in this manner.
Fixes#821. If a node isn't opened in NERDTree, it's children aren't
known yet, so when deleting the node (with `m`, `d`), the user isn't
properly asked to confirm the delete. It was going to the less strict
`Y`/`n` confirmation, instead of the `yes` confirmation for non-empty
directories.
This change checks to see if the node is opened already. If it is, the
existing getChildCount() function is used; otherwise, the disk is read
to get the number of children there.
If the user wipes out or deletes (:bw or :bd) the NERDTree buffer, there
is still a tab variable that hangs onto the name of that now-missing
buffer. Checking only that variable is not enough to decide whether to
create a new NERDTree or use the existing one. Fortunately, there
already is a function with a more complete check: ExistsForTab()
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.