From c934b50c0d59b98ec5424b171575e46d7b230e2a Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 19 Jun 2017 17:28:41 -0400 Subject: [PATCH] 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 "" Vim key code. Since "" is always triggered before "", 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 "" instead of "" in the mapping. As an enhancement, I added the trigger of a "" 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. --- autoload/nerdtree/ui_glue.vim | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 2478fd3..90ce872 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -7,7 +7,7 @@ let g:loaded_nerdtree_ui_glue_autoload = 1 function! nerdtree#ui_glue#createDefaultBindings() let s = '' . s:SID() . '_' - call NERDTreeAddKeyMap({ 'key': '', 'scope': "all", 'callback': s."handleMiddleMouse" }) + call NERDTreeAddKeyMap({ 'key': '', 'scope': 'all', 'callback': s . 'handleMiddleMouse' }) call NERDTreeAddKeyMap({ 'key': '', 'scope': "all", 'callback': s."handleLeftClick" }) call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "DirNode", 'callback': s."activateDirNode" }) call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."activateFileNode" }) @@ -336,16 +336,22 @@ endfunction " FUNCTION: s:handleMiddleMouse() {{{1 function! s:handleMiddleMouse() - let curNode = g:NERDTreeFileNode.GetSelected() - if curNode ==# {} - call nerdtree#echo("Put the cursor on a node first" ) + + " A middle mouse click does not automatically position the cursor as one + " would expect. Forcing the execution of a regular left mouse click here + " fixes this problem. + execute "normal! \" + + let l:currentNode = g:NERDTreeFileNode.GetSelected() + if empty(l:currentNode) + call nerdtree#echoError('use the pointer to select a node') return endif - if curNode.path.isDirectory - call nerdtree#openExplorer(curNode) + if l:currentNode.path.isDirectory + call l:currentNode.openExplorer() else - call curNode.open({'where': 'h'}) + call l:currentNode.open({'where': 'h'}) endif endfunction