Skip to content

Commit 1e0d1cb

Browse files
committed
move some more view code into the UI class
1 parent eaa66aa commit 1e0d1cb

File tree

3 files changed

+80
-48
lines changed

3 files changed

+80
-48
lines changed

autoload/nerdtree.vim

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,6 @@ endfunction
126126
" SECTION: View Functions {{{1
127127
"============================================================
128128
"
129-
"FUNCTION: nerdtree#centerView() {{{2
130-
"centers the nerd tree window around the cursor (provided the nerd tree
131-
"options permit)
132-
function! nerdtree#centerView()
133-
if g:NERDTreeAutoCenter
134-
let current_line = winline()
135-
let lines_to_top = current_line
136-
let lines_to_bottom = winheight(nerdtree#getTreeWinNum()) - current_line
137-
if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold
138-
normal! zz
139-
endif
140-
endif
141-
endfunction
142-
143129
" FUNCTION: nerdtree#chRoot(node) {{{2
144130
" changes the current root to the selected one
145131
function! nerdtree#chRoot(node)

autoload/nerdtree/ui_glue.vim

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ endfunction
243243
function! s:displayHelp()
244244
let b:treeShowHelp = b:treeShowHelp ? 0 : 1
245245
call b:NERDTree.render()
246-
call nerdtree#centerView()
246+
call b:NERDTree.ui.centerView()
247247
endfunction
248248

249249
" FUNCTION: s:findAndRevealPath() {{{1
@@ -372,7 +372,7 @@ function! s:jumpToChild(currentNode, direction)
372372

373373
call targetNode.putCursorHere(1, 0)
374374

375-
call nerdtree#centerView()
375+
call b:NERDTree.ui.centerView()
376376
endfunction
377377

378378

@@ -400,7 +400,7 @@ endfunction
400400
function! s:jumpToParent(node)
401401
if !empty(a:node.parent)
402402
call a:node.parent.putCursorHere(1, 0)
403-
call nerdtree#centerView()
403+
call b:NERDTree.ui.centerView()
404404
else
405405
call nerdtree#echo("cannot jump to parent")
406406
endif
@@ -410,7 +410,7 @@ endfunction
410410
" moves the cursor to the root node
411411
function! s:jumpToRoot()
412412
call b:NERDTreeRoot.putCursorHere(1, 0)
413-
call nerdtree#centerView()
413+
call b:NERDTree.ui.centerView()
414414
endfunction
415415

416416
" FUNCTION: s:jumpToNextSibling(node) {{{1
@@ -434,7 +434,7 @@ function! s:jumpToSibling(currentNode, forward)
434434

435435
if !empty(sibling)
436436
call sibling.putCursorHere(1, 0)
437-
call nerdtree#centerView()
437+
call b:NERDTree.ui.centerView()
438438
endif
439439
endfunction
440440

@@ -570,53 +570,29 @@ function! s:showMenu(node)
570570
endfunction
571571

572572
" FUNCTION: s:toggleIgnoreFilter() {{{1
573-
" toggles the use of the NERDTreeIgnore option
574573
function! s:toggleIgnoreFilter()
575-
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled
576-
call b:NERDTree.ui.renderViewSavingPosition()
577-
call nerdtree#centerView()
574+
call b:NERDTree.ui.toggleIgnoreFilter()
578575
endfunction
579576

580577
" FUNCTION: s:toggleShowBookmarks() {{{1
581-
" toggles the display of bookmarks
582578
function! s:toggleShowBookmarks()
583-
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
584-
if b:NERDTreeShowBookmarks
585-
call b:NERDTree.render()
586-
call nerdtree#putCursorOnBookmarkTable()
587-
else
588-
call b:NERDTree.ui.renderViewSavingPosition()
589-
endif
590-
call nerdtree#centerView()
579+
call b:NERDTree.ui.toggleShowBookmarks()
591580
endfunction
592581

593582
" FUNCTION: s:toggleShowFiles() {{{1
594-
" toggles the display of hidden files
595583
function! s:toggleShowFiles()
596-
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles
597-
call b:NERDTree.ui.renderViewSavingPosition()
598-
call nerdtree#centerView()
584+
call b:NERDTree.ui.toggleShowFiles()
599585
endfunction
600586

601587
" FUNCTION: s:toggleShowHidden() {{{1
602588
" toggles the display of hidden files
603589
function! s:toggleShowHidden()
604-
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden
605-
call b:NERDTree.ui.renderViewSavingPosition()
606-
call nerdtree#centerView()
590+
call b:NERDTree.ui.toggleShowHidden()
607591
endfunction
608592

609593
" FUNCTION: s:toggleZoom() {{{1
610-
" zoom (maximize/minimize) the NERDTree window
611594
function! s:toggleZoom()
612-
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed
613-
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
614-
exec "silent vertical resize ". size
615-
let b:NERDTreeZoomed = 0
616-
else
617-
exec "vertical resize"
618-
let b:NERDTreeZoomed = 1
619-
endif
595+
call b:NERDTree.ui.toggleZoom()
620596
endfunction
621597

622598
"FUNCTION: nerdtree#ui_glue#upDir(keepState) {{{1

lib/nerdtree/ui.vim

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
let s:UI = {}
44
let g:NERDTreeUI = s:UI
55

6+
7+
function! s:UI.lolcats()
8+
echomsg "lolcats"
9+
endfunction
10+
11+
"FUNCTION: s:UI.centerView() {{{2
12+
"centers the nerd tree window around the cursor (provided the nerd tree
13+
"options permit)
14+
function! s:UI.centerView()
15+
if g:NERDTreeAutoCenter
16+
let current_line = winline()
17+
let lines_to_top = current_line
18+
let lines_to_bottom = winheight(nerdtree#getTreeWinNum()) - current_line
19+
if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold
20+
normal! zz
21+
endif
22+
endif
23+
endfunction
24+
25+
"FUNCTION: s:UI.new(nerdtree) {{{1
626
function! s:UI.New(nerdtree)
727
let newObj = copy(self)
828
let newObj.nerdtree = a:nerdtree
@@ -260,3 +280,53 @@ function! s:UI.renderViewSavingPosition()
260280
call currentNode.putCursorHere(0, 0)
261281
endif
262282
endfunction
283+
284+
" FUNCTION: s:UI.toggleIgnoreFilter() {{{1
285+
" toggles the use of the NERDTreeIgnore option
286+
function! s:UI.toggleIgnoreFilter()
287+
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled
288+
call b:NERDTree.ui.renderViewSavingPosition()
289+
call b:NERDTree.ui.centerView()
290+
endfunction
291+
292+
" FUNCTION: s:UI.toggleShowBookmarks() {{{1
293+
" toggles the display of bookmarks
294+
function! s:UI.toggleShowBookmarks()
295+
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
296+
if b:NERDTreeShowBookmarks
297+
call b:NERDTree.render()
298+
call nerdtree#putCursorOnBookmarkTable()
299+
else
300+
call b:NERDTree.ui.renderViewSavingPosition()
301+
endif
302+
call b:NERDTree.ui.centerView()
303+
endfunction
304+
305+
" FUNCTION: s:UI.toggleShowFiles() {{{1
306+
" toggles the display of hidden files
307+
function! s:UI.toggleShowFiles()
308+
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles
309+
call b:NERDTree.ui.renderViewSavingPosition()
310+
call b:NERDTree.ui.centerView()
311+
endfunction
312+
313+
" FUNCTION: s:UI.toggleShowHidden() {{{1
314+
" toggles the display of hidden files
315+
function! s:UI.toggleShowHidden()
316+
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden
317+
call b:NERDTree.ui.renderViewSavingPosition()
318+
call self.centerView()
319+
endfunction
320+
321+
" FUNCTION: s:UI.toggleZoom() {{{1
322+
" zoom (maximize/minimize) the NERDTree window
323+
function! s:UI.toggleZoom()
324+
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed
325+
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
326+
exec "silent vertical resize ". size
327+
let b:NERDTreeZoomed = 0
328+
else
329+
exec "vertical resize"
330+
let b:NERDTreeZoomed = 1
331+
endif
332+
endfunction

0 commit comments

Comments
 (0)