nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 53bc77644c8149ae995918b9d6f544cc31813346
parent 6782ec01047fc5ee48599932d72fb4c0961671d1
Author: Martin Grenfell <martin.grenfell@gmail.com>
Date:   Wed, 11 Jan 2012 13:08:08 +0000

refactor KeyMap so we dont use index() on an array of objects

Dont do `remove(array_of_prototype_obs, index(...)))`. In the past this
has been found to cause seg faults when the objects get large.

Diffstat:
Mplugin/NERD_tree.vim | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim
@@ -520,6 +520,15 @@ function! s:KeyMap.bind()
     exec 'nnoremap <buffer> <silent> '. mapkey . premap . ':call <SID>KeyMap_Invoke("'. self.key .'")<cr>'
 endfunction
 
+"FUNCTION: KeyMap.Remove(key, scope) {{{3
+function! s:KeyMap.Remove(key, scope)
+    let maps = s:KeyMap.All()
+    for i in range(len(maps))
+         if maps[i].key ==# a:key && maps[i].scope ==# a:scope
+            return remove(maps, i)
+        endif
+    endfor
+endfunction
 "FUNCTION: KeyMap.invoke() {{{3
 "Call the KeyMaps callback function
 function! s:KeyMap.invoke(...)
@@ -606,11 +615,7 @@ endfunction
 
 "FUNCTION: KeyMap.Add(keymap) {{{3
 function! s:KeyMap.Add(keymap)
-    let oldmap = s:KeyMap.FindFor(a:keymap.key, a:keymap.scope)
-    if !empty(oldmap)
-        call remove(s:KeyMap.All(), index(s:KeyMap.All(), oldmap))
-    endif
-
+    call s:KeyMap.Remove(a:keymap.key, a:keymap.scope)
     call add(s:KeyMap.All(), a:keymap)
 endfunction