From 62c94e272f414f74c92c99b35d0421365dc7973f Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Tue, 3 Jan 2012 22:43:18 +0000 Subject: [PATCH] fix the mouse mappings --- plugin/NERD_tree.vim | 61 +++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 2de401c..cedf0ac 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -3663,8 +3663,8 @@ endfunction function! s:bindMappings() " set up mappings and commands for this buffer nnoremap :call handleMiddleMouse() - nnoremap :call checkForActivate() - nnoremap <2-leftmouse> :call activateNode(0) + nnoremap :call handleLeftClick() + exec "nnoremap <2-leftmouse> :call KeyMap_Invoke('". g:NERDTreeMapActivateNode ."')" let s = '' . s:SID() . '_' @@ -3753,29 +3753,6 @@ function! s:bookmarkNode(...) call s:echo("select a node first") endif endfunction -"FUNCTION: s:checkForActivate() {{{2 -"Checks if the click should open the current node -function! s:checkForActivate() - let currentNode = s:TreeFileNode.GetSelected() - if currentNode != {} - let startToCur = strpart(getline(line(".")), 0, col(".")) - - if currentNode.path.isDirectory - if startToCur =~# s:tree_markup_reg . '$' && startToCur =~# '[+~▾▸]$' - call s:activateNode(0) - return - endif - endif - - if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3 - let char = strpart(startToCur, strlen(startToCur)-1, 1) - if char !~# s:tree_markup_reg - call s:activateNode(0) - return - endif - endif - endif -endfunction " FUNCTION: s:chCwd(node) {{{2 function! s:chCwd(node) @@ -3868,6 +3845,38 @@ function! s:displayHelp() call s:centerView() endfunction +"FUNCTION: s:handleLeftClick() {{{2 +"Checks if the click should open the current node +function! s:handleLeftClick() + let currentNode = s:TreeFileNode.GetSelected() + if currentNode != {} + + "the dir arrows are multibyte chars, and vim's string functions only + "deal with single bytes - so split the line up with the hack below and + "take the line substring manually + let line = split(getline(line(".")), '\zs') + let startToCur = "" + for i in range(0,virtcol(".")-1) + let startToCur .= line[i] + endfor + + if currentNode.path.isDirectory + if startToCur =~# s:tree_markup_reg . '$' && startToCur =~# '[+~▾▸]$' + call s:activateNode(currentNode) + return + endif + endif + + if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3 + let char = strpart(startToCur, strlen(startToCur)-1, 1) + if char !~# s:tree_markup_reg + call s:activateAll() + return + endif + endif + endif +endfunction + " FUNCTION: s:handleMiddleMouse() {{{2 function! s:handleMiddleMouse() let curNode = s:TreeFileNode.GetSelected() @@ -3877,7 +3886,7 @@ function! s:handleMiddleMouse() endif if curNode.path.isDirectory - call s:openExplorer() + call s:openExplorer(curNode) else call s:openEntrySplit(0,0) endif