From 43bf05c42e3976b9f55151d7d27ede5af94bcd17 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Mon, 7 Jul 2008 21:08:02 +1200 Subject: [PATCH] jump to the bookmarks table after opening it when the user hits B and opens the bookmarks table, stick the cursor at the top of it --- doc/NERD_tree.txt | 1 + plugin/NERD_tree.vim | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt index 7ca8f35..2ff1cdd 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERD_tree.txt @@ -877,6 +877,7 @@ fridge for later ;) 2.x.x - make the t/T on directory nodes open a fresh NERD tree for the selected dir in a new tab, rather than a netrw. + - place the cursor at the top of the bookmarks table when opening it with B 2.12.0 - added a UI for bookmarks. See :help NERDTreeBookmarkTable for details. diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 1b68785..5012e3c 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -2368,6 +2368,25 @@ function! s:PromptToDelBuffer(bufnum, msg) endif endfunction +"FUNCTION: s:PutCursorOnBookmarkTable(){{{2 +"Places the cursor at the top of the bookmarks table +function! s:PutCursorOnBookmarkTable() + if !t:NERDTreeShowBookmarks + throw "NERDTree.IllegalOperation exception: cant find bookmark table, bookmarks arent active" + endif + + let rootNodeLine = s:FindRootNodeLineNumber() + + let line = 1 + while getline(line) !~ '^>-\+Bookmarks-\+$' + let line = line + 1 + if line >= rootNodeLine + throw "NERDTree.BookmarkTableNotFound exception: didnt find the bookmarks table" + endif + endwhile + call cursor(line, 0) +endfunction + "FUNCTION: s:PutCursorOnNode(treenode, isJump, recurseUpward){{{2 "Places the cursor on the line number representing the given node " @@ -3390,7 +3409,12 @@ endfunction " toggles the display of bookmarks function! s:ToggleShowBookmarks() let t:NERDTreeShowBookmarks = !t:NERDTreeShowBookmarks - call s:RenderViewSavingPosition() + if t:NERDTreeShowBookmarks + call s:RenderView() + call s:PutCursorOnBookmarkTable() + else + call s:RenderViewSavingPosition() + endif call s:CenterView() endfunction " FUNCTION: s:ToggleShowFiles() {{{2