Commit Graph

140 Commits

Author SHA1 Message Date
Jason Franklin
f9e83ad8bd Fix a bug with the 'u' mapping
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.
2018-05-06 12:19:19 -04:00
Jason Franklin
2437b75479 Remove unsupported bookmark table mappings
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.
2018-04-28 09:17:29 -04:00
Jason Franklin
0ff697eb40 Implement the "isHiddenUnder()" method for Path 2017-12-22 10:28:31 -05:00
Jason Franklin
01b011d38e Have "finAndRevealPath()" fail on no file
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.
2017-12-22 08:45:57 -05:00
Jason Franklin
344119439e Refresh children of directory nodes on "reveal()"
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.
2017-12-21 10:36:16 -05:00
Jason Franklin
90d08dc626 Add a debugging message 2017-12-21 09:26:26 -05:00
Jason Franklin
5301dd24fb Improve variable naming in "findAndRevealPath" 2017-12-21 08:43:15 -05:00
Jason Franklin
496d9a17d8 Remove code duplication in "findAndRevealPath" 2017-12-21 08:28:28 -05:00
Jason Franklin
b4b99c39fa Change the type of completion used by NERDTreeFind
This command should complete file names, not directories.

Fixes #780.
2017-12-12 08:24:18 -05:00
Jason Franklin
2129740419 Add style improvements
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.
2017-12-09 11:09:10 -05:00
zhenyangze
12960b966f change NERDTreeFind with args 2017-12-09 16:58:18 +08:00
Jason Franklin
e48ae299f9 Update the delete bookmark map to use confirm()
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.
2017-12-01 08:45:18 -05:00
Jason Franklin
ac94cd28c2 Make the "o" mapping consistent with "x"
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.
2017-11-19 16:37:54 -05:00
Jason Franklin
e0e36c5385
Fix a problem with the "x" handler (#768)
Pressing "x" on a cascade could close the root of the tree.  This
commit prevents that from happening.
2017-11-18 10:55:43 -05:00
Jason Franklin
f526c4e652
Clean up the handler for the "x" mapping (#767)
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.
2017-11-18 09:51:34 -05:00
Jason Franklin
c9f7014034 Fix handlers for "t" and "T" on bookmarks
The "t" and "T" mappings didn't work on bookmarks.  This commit
fixes this problem by making the callbacks more general.

Fixes #565.
2017-11-11 12:10:08 -05:00
Jason Franklin
ae1c95bcbc Explicitly call open() in "ui_glue.vim" callbacks
This bug is subtle!  Opening a directory node in a new tab (with the
"t" or "T" mappings) would previously fail and require a refresh
because it called the directory node's "activate()" method.

In reviewing that method (i.e., "activate()"), I discovered that the
directory node's NERDTree is rendered before the method returns,
which overwrites the content of the tree in the new tab or window.

To clarify, when "t" or "T" is used on a directory node, a new
directory node and tree must be created to be rendered in a new tab.
So, calling "self.getNerdtree().render()" at the bottom of
"activate()" will render the NERDTree instance from which "t" or "T"
was invoked, not the new NERDTree that is being displayed.  This
overwrites the new NERDTree text, and, thus, a refresh is required.

Since a call to "render()" is almost always necessary at the bottom
of "activate()" to keep everything in sync for other mappings, we
avoid this problem entirely by using the "open()" method directly
(works for files and directories) in the callbacks.

Fixes #549.
2017-11-11 11:19:16 -05:00
Alexey Shumkin
cb9f4db6ff fixed: directory navigation does not work on Cygwin
Directory tree navigation is broken because of directory signs which is
shown in UTF-8.

Cygwin is a Windows application, so it uses ASCII codepages and so
directory signs must be in ASCII, but if to modify
"nerdtree#runningWindows" function there are many other functions break
that convert paths, e.g.

So, the quick and reliable solution is to add a
separate function "nerdtree#runningCygwin" and use it in a specific
place.
2017-10-27 10:06:51 +03:00
Jason Franklin
49c165a103 Update the function that drives the p mapping
As reported in issue #67, the function driving the `p` mapping was
not updated to work as expected when the cursor is positioned on a
cascade. This problem is addressed here.

Fixes #67.
2017-07-08 11:33:10 -04:00
Phil Runninger
626e80f6e4 Merge pull request #536 from satori/master
Add support for natural sorting order.
2017-06-21 11:33:47 -04:00
Jason Franklin
c934b50c0d Repair the broken middle mouse click handler
Issues #597, #642, and #650 all report problems with the NERDTree
handler function for middle mouse clicks. In all cases, the problems
arose from the use of a function that didn't exist and from the use
of a bad argument in the call to the "g:NERDTreeAddKeyMap" function.
The fix for the first problem is obvious, but the solution to the
second bug merits explanation.

Previously, middle click events in the NERDTree window were
triggered with the "<MiddleRelease>" Vim key code. Since
"<MiddleMouse>" is always triggered before "<MiddleRelease>", The
error in #642 was bound to occur (because of the default behavior
for middle mouse clicks). Thus, the problem was easily solved by
using "<MiddleMouse>" instead of "<MiddleRelease>" in the mapping.

As an enhancement, I added the trigger of a "<LeftMouse>" event as
the first command in the handler function. This will cause the
middle click to reposition the cursor below the pointer before
continuing with its normal behavior. The benefits of this are clear.

This mapping has no defined behavior for bookmarks. Unless an issue
is raised to address this, it will be left just so for now.

Fixes #597, fixes #642, and fixes #650.
2017-06-19 17:28:41 -04:00
Jason Franklin
3063dfb766 Refactor the :OpenBookmark command
I altered the behavior of the ":OpenBookmark" command to match that of
the "NERDTree-o" mapping. This is acceptable for the following reasons:

 1. It was broken, so no one was using it.
 2. The name matches its behavior.

If a bookmark is to be opened in an explorer window, we should have a
command with a matching name for that behavior (":ExploreBookmark", for
example). This can be added later if there is enough demand for the
feature. Otherwise, this is a perfectly valid change.
2017-06-10 15:59:56 -04:00
Jason Franklin
0b65089122 Reimplement the bookmark comparison method
Sorting the list of user bookmarks requires care to ensure that Vim's
builtin sort function is called correctly. Previously, this function was
called incorrectly. This is why the sorting of bookmarks never worked.

The offending functions have been removed here and replaced with
"s:Bookmark.CompareBookmarksByName". To understand the necessity for
this change, read ":h sort()" for the requirements of the function
reference argument (esp., note that it must return -1, 0, or 1).

In addition to fixing this problem, the new comparison function will
inspect the "g:NERDTreeBookmarksSort" setting to determine whether
case-sensitivity is preferred in the sort. The documentation has been
modified to accurately reflect this adjustment. The change is also made
in such a way as not to break any existing configurations.

Fixes #361 ("My bookmarks aren't sorted").
2017-05-26 13:23:05 -04:00
Phil Runninger
d99967cadd Revert "Determine if we're running in Cygwin on Windows." 2017-05-23 07:15:35 -04:00
Phil Runninger
fce10d1b10 Merge pull request #626 from scrooloose/win32unix
Determine if we're running in Cygwin on Windows.
2017-05-20 03:25:38 -04:00
Greg Hurrell
0c0bde3106 Update stale comments
@lifecrisis pointed out this stale comment here:

https://github.com/scrooloose/nerdtree/pull/578#issuecomment-302392831

Closes: #640
2017-05-18 07:02:02 -07:00
Phil Runninger
45f4d61f04 Merge pull request #578 from wincent/eventignore
Suppress autocmds less aggressively
2017-04-12 09:50:28 -04:00
Martin Grenfell
eee431dbd4 really fix the previous buffer issue when closing a tree win
So :bprev was failing to jump back to the right buffer. I dont fully
understand this yet, but I'm fairly sure this is because there is a
magic <directory> buffer that we delete when creating a wintree :-/

Anyway, we are explicitly storing the prev buffer again - and updating
it when reusing treewins. It's worky, but there may be a superior way...
2016-10-21 14:48:05 +01:00
Martin Grenfell
48df6bfd6e Revert "remove NERDTree.previousBuf() and related code"
This reverts commit 2027ae03db.
2016-10-21 14:40:18 +01:00
Martin Grenfell
2027ae03db remove NERDTree.previousBuf() and related code
We were using this when closing a wintree - to go to the previous
buffer. Not sure why we weren't just using `:bprev` ...
2016-10-19 13:28:44 +01:00
Phil Runninger
4477078170 Unlet! the nt variable before letting it.
Some will have a "NERDTree" buffer variable and others will not. In the
ones that do, getbufvar will return a dictionary. getbufvar will return
an empty string from the other buffers. When looping through the buffers,
let will throw an error if nt already exists and is a different type than
what is trying to be put into it. This easily can be illustrated by these
two statements:

:let x = ""
:let x = {}
E706: Variable type mismatch for: x

This commit gets rid of the variable before setting it so that the
mismatch cannot occur.
2016-10-17 10:30:33 -04:00
Martin Grenfell
84e7a77a7e reuse win trees when editing the same dir again
If you do

```
:edit some/dir/
```

then do the same thing at a later point, then the same nerdtree buffer
will be loaded/shown the second time.
2016-10-14 16:34:08 +01:00
Phil Runninger
a9a5aec9c0 Determine if we're running in Cygwin on Windows. 2016-10-06 17:51:22 -04:00
Łukasz Adamczak
2924ab2071 Verify we haven't reached root when traversing cascade 2016-06-22 13:59:49 +02:00
Łukasz Adamczak
c99312442b Fix upward traversal when closing a cascade 2016-06-22 13:32:44 +02:00
Greg Hurrell
35b04fa3df Suppress autocmds less aggressively
This is the counterpart to a PR I just submitted to undotree
(https://github.com/mbbill/undotree/pull/61).

I noticed that my statusline doesn't update properly when using NERDTree to move
between revisions of a file with `go` or `gi`
(https://github.com/wincent/wincent/issues/16). I established that this was
because it was using `'eventignore'` to suppress all autocmds, which in turn
prevents the statusline from updating.

Commenting out the `set eventignore=all` line makes the failure to update go
away, at the cost of firing more autocmds.

I considered adding an option for opting out of this behavior (eg. `let
g:NERDTreeEventignore=0` or something), or rearchitecting my statusline to use
an approach like vim-airline does based on CursorMoved autocmds (see
https://github.com/vim-airline/vim-airline/issues/82; see also
30f078daf5/plugin/airline.vim (L36-L50)
for current implementation), but then realized that a simpler fix is to have
NERDTree just disable only the autocmds that it uses instead of disabling all of
them.

This is probably not enough to unbreak every bit of code in the world that
depends on those autocmds, but it does at least unbreak my use case, because it
allows my `WinLeave` autocmd to run and update the statusline.
2016-05-05 09:35:16 -07:00
brook hong
e2bbedff09 Fix #520 E716: Key not present in Dictionary: setShowHidden 2016-02-02 22:31:17 +08:00
Maxim Bublis
6251ab1e63 Add support for natural sorting order. 2016-01-19 00:21:13 -08:00
Martin Grenfell
4ebbb533c3 silence bookmark errors on startup
Just disable the warning for now. The bookmark system will be replaced
with the project system soon - so no sense putting much effort into
this.

Closes #168
2015-12-02 21:17:22 +00:00
Martin Grenfell
665f326577 remove dependency on b:NERDTree from classes that dont need it
Inject it where needed.
2015-11-20 01:44:12 +00:00
Martin Grenfell
cedb40b4f5 move TreeFileNode.makeRoot() to NERDTree.changeRoot(node) 2015-11-16 13:17:59 +00:00
Martin Grenfell
d36b793656 dont use b:NERDTreeRoot internally, but leave the var there for compat
Use b:NERDTree.root instead. I will eventually remove  b:NERDTreeRoot
altogether - but this will break some other plugins so leave it for now.
2015-11-16 11:28:24 +00:00
Martin Grenfell
0b966aa23a refactor TreeDirNode.reveal slightly 2015-11-16 09:35:31 +00:00
Martin Grenfell
83d108894e move a bunch of b:NERDTree.* vars into the b:NERDTree.ui obj 2015-11-15 00:45:57 +00:00
Martin Grenfell
4d8a0c90cb move b:NERDTreePreviousBuf into NERDTree class 2015-11-14 13:10:08 +00:00
Martin Grenfell
5c20274761 move b:NERDTreeType into the NERDTree class and add some query methods 2015-11-14 12:01:55 +00:00
Martin Grenfell
848857d18b rename "primary" and "secondary" trees to "tab" and "window" trees
This is much more accurate and descriptive.
2015-11-14 11:50:01 +00:00
Martin Grenfell
4dada8c04f update version number to 5.0.0 2015-11-13 16:57:21 +00:00
Igor Tatarintsev
dc29ec2db3 Added global variables for changing default arrows
g:NERDTreeDirArrowExpandable
g:NERDTreeDirArrowCollapsable
2015-09-11 23:52:37 +06:00
Igor Tatarintsev
188bd92658 Added global variables for changing default arrows 2015-09-11 23:44:06 +06:00
toiffel
93c9726c6d Fixed case-sensitive sorting of tree nodes when 'ignorecase' option is on 2015-07-13 03:03:14 +06:00
Vincent Tsang
80e184df56 Refactor code to use getSortKey() and replace regular expression with
simple string comparison in tree_dir_node.vim
2015-05-11 11:56:08 +08:00
Vincent Tsang
57d5bd7731 Speed up sortChildren() by using sorting token
This improves the sorting functions from 12 seconds to 0.66 seconds for
~4000 objects
2015-05-09 22:47:33 +08:00
Martin Grenfell
a87b1bf3c5 Merge branch 'update_reuse_option' 2015-05-06 21:42:03 +01:00
Martin Grenfell
8b189cb263 move some rendering and cursor moving functions out of autoload 2015-05-02 15:24:59 +01:00
Martin Grenfell
b0114d202b move dumpHelp out of autoload 2015-05-02 15:05:28 +01:00
Martin Grenfell
53d2de86eb move the closeTree functions out of autoload
Remove `closeTreeIfOpen` and just make `closeTree` fail silently.
2015-05-02 15:03:54 +01:00
Martin Grenfell
0d88ce946f move isTreeOpen() out of autoload 2015-05-02 14:44:32 +01:00
Martin Grenfell
8270b6d717 move nerdtree#getTreeWinNum out of autoload 2015-05-02 14:32:21 +01:00
Martin Grenfell
973c9906f8 refactor 3 more functions out of the monolithic autoload file 2015-05-02 14:17:52 +01:00
Martin Grenfell
f8499462c5 Revert "Use different arrow characters for compatibility."
This reverts commit f6cad7e957.
2015-05-02 11:29:43 +01:00
Martin Grenfell
186f817f5a Revert "fix one of the old style arrows"
This reverts commit b3281cc63e.
2015-05-02 11:28:54 +01:00
Martin Grenfell
b3281cc63e fix one of the old style arrows
See here: 1cbd52aa77
2015-05-01 16:01:26 +01:00
Martin Grenfell
87b27802b5 allow control over whether to reuse windows in different tabs
When opening a file we will "reuse" a window if the buffer is already
open somewhere.

Add an option to NERDTreeOpener to configure it to not reuse windows
across tabs.
2015-05-01 15:33:06 +01:00
Curtiss Howard
f6cad7e957 Use different arrow characters for compatibility. 2015-04-17 17:36:23 -04:00
Martin Grenfell
c2dd750860 move nerdtree#treeExists.* methods into the NERDTree class 2014-07-17 20:31:17 +01:00
Martin Grenfell
fd14757c04 add proper events and make the notifier class generic
Expand the event system to have explicit Event objects and potentially
many Notifiers. Previously they was only one notifier and one (implied)
event.

A lot of this is stolen from #358.
2014-07-17 20:18:09 +01:00
Martin Grenfell
0c045d85ea fix a bug from recent refactoring RE some NERDTreeCWD 2014-07-14 09:43:45 +01:00
Martin Grenfell
9f351de594 Merge branch 'master' into expt_add_path_flags_and_git 2014-07-09 09:26:17 +01:00
Martin Grenfell
1e0d1cbc8f move some more view code into the UI class 2014-07-09 09:25:25 +01:00
Martin Grenfell
2f59cc2080 Merge branch 'master' into expt_add_path_flags_and_git 2014-07-08 09:47:38 +01:00
Martin Grenfell
eaa66aaf63 fix the NERDTreeFind command - broken in recent refactoring 2014-07-08 09:45:24 +01:00
Martin Grenfell
8644622000 Merge branch 'master' into expt_add_path_flags_and_git
Conflicts:
	autoload/nerdtree.vim
	lib/nerdtree/creator.vim
2014-07-08 09:38:43 +01:00
Martin Grenfell
23dfc6d818 continue breaking down the epic autoload module
Add 2 new classes and move code into them from autoload:

* NERDTree. Each nerdtree buffer now has a NERDTree object that holds
  the root node and will old other util functions
* UI. Each NERDTree object holds a UI object which is responsible for
  rendering, getting the current node, etc

Still a fair few methods to sort through in autoload (many of which will
end up in the above classes) - need sleep though.
2014-07-07 22:59:28 +01:00
Martin Grenfell
f982f61e8a continue breaking up the autoload/nerdtree god module 2014-07-07 21:34:57 +01:00
Martin Grenfell
86488b1aa0 move ui functions out into their own autoload
All of the autoload shit needs to be cleaned up... break it out first
2014-07-07 19:36:34 +01:00
Martin Grenfell
32cf3ee62d allow flags to be scoped to a plugin
Add new FlagSet class and init each Path with one.

Call Path.flagSet.addFlag(scope, flag) instead of Path.addFlag(flag)
2014-07-05 20:51:21 +01:00
Martin Grenfell
a7428eba38 add proof of concept for path flags API and add git modified flags 2014-07-05 00:29:45 +01:00
Martin Grenfell
55a8954c48 update the doc/quickhelp for :Bookmark
Make it clearer that the argument is optional.

Closes #229
2014-06-29 12:37:29 +01:00
pendulm
6ef67a2d8e Add correspoding close action to cascade open single child dir 2013-04-22 23:39:26 +08:00
Martin Grenfell
eaf19734e7 move the class files out of the plugin dir
On some new versions of vim these files were being loaded before the
main NERD_tree.vim which was causing errors as dependencies werent
loaded in time. Move the classes into lib - so vim wont try to load them
until we tell it
2013-04-13 20:32:25 +01:00
Martin Grenfell
f93d2c79e5 fix NERDTreeCWD
Closes #233
2013-04-03 13:39:10 +01:00
Martin Grenfell
64cb6204cc move a couple of functions into NERDTreeCreator
The "next buffer name" functions are only used in NERDTreeCreator so put
them there.
2013-01-09 09:51:28 +00:00
Martin Grenfell
c3b63d2fd9 add some class methods to wrap the NERDTreeCreator public methods
This is needed because some versions of vim dont let you chain method
calls together. So do the work in NERDTreeCreator instead of forcing all
callers to break the New().createXXX() calls out onto 2 lines with an
intermediate variable.

Fixes #226.
2013-01-09 00:43:37 +00:00
Martin Grenfell
25b80b8a16 extract the tree creation functions out into their own class
Add the NERDTreeCreator class.

Stick all functions related to creating a primary/secondary/mirror
nerdtree in there. We may break this down further in the future, but
this is a good starting point.

Make some of the interface binding functions in autoload/nerdtree
public. This is needed since we are accessing some of them from
NERDTreeCreator. Should be temporary until we get some kind of proper
interface binding system set up.
2013-01-08 00:04:30 +00:00
Martin Grenfell
a7d5b3dbc1 fix the <enter> mapping
It now acts the same as the ActivateNode mapping ('o' by default) again.
This was broken in the big refactor.

Fixes #222
2013-01-05 11:58:36 +00:00
Martin Grenfell
cc0777b792 move KeyMap_Invoke into the autoload file
This will keep the class file cleaner, and may also fix #223
2013-01-05 11:44:48 +00:00
Martin Grenfell
8a984260e7 manually apply #220 to fix NERDTreeFind for hidden dirs 2013-01-05 01:48:13 +00:00
Martin Grenfell
370f180ca0 replace a script level var with a query 2013-01-05 01:47:20 +00:00
Martin Grenfell
fb4a5a116a decompose the giant NERD_tree.vim file
* Move the classes out into `plugin/nerdtree/<classname>`.
* Move the other functions out into `autoload/nerdtree.vim`.

Stuff still to do:

* extract out at least one view class from `autoload/nerdtree` -
  something like NERDTreeWindow
* figure out which functions in autoload/nerdtree should be scoped to
  the script instead of public
2013-01-05 01:08:06 +00:00