When the user has `'autochdir'` turned on, opening a new NERDTree will
cause the current working directory to change. To prevent this
happening, remember the CWD and reset it if NERDTreeFocus caused it to
change.
If the cursor is not already positioned on a node when the bookmark
table is closed, then the resulting position of the cursor is not
determined. Here, we default to positioning the cursor on the
root when the bookmark table is closed.
Also add a new global variable to track when the g:NERDTreeSortOrder
changes. If it has been changed, or when the cached _sortKey value is
uninitialized, then calculate the sort key. This improves processing
speed over the previous commit, and allows on-the-fly changes to the
sort order, (without required vim to be restarted.)
The call to AddDefaultGroupToSortOrder in NERD_tree.vim is redundant
because it's also done every time sortChildren is called. And since the
check is done only once, there's no need for a function either.
sortChildren now just contains the needed if statement.
This commit makes adding, removing and finding key maps an O(1)
operation instead of O(n), where n is the number of pre-existing maps.
In my testing, averaged over 100 iterations, this reduces the time spent
initializing NERDTree at Vim startup from ~73ms to ~9.7ms. That's with
only the default included key maps.
Using the ":clearjumps" command wipes out the jump list for the
current window. This means that the user can't inadvertently jump
out of the NERDTree buffer while using the NERDTree window (i.e., by
using "<C-O>").
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.