--- a/plugin/gundo.vim Tue Oct 12 18:48:47 2010 -0400
+++ b/plugin/gundo.vim Tue Oct 12 19:06:02 2010 -0400
@@ -22,38 +22,23 @@
"}}}
"{{{ Movement Mappings
-function! s:GundoMoveUp()
+function! s:GundoMove(direction)
let start_line = getline('.')
- if line('.') - 2 <= 4
- call cursor(5, 0)
- elseif stridx(start_line, '[') == -1
- call cursor(line('.') - 1, 0)
+
+ if stridx(start_line, '[') == -1
+ let distance = 1
else
- call cursor(line('.') - 2, 0)
+ let distance = 2
endif
- let line = getline('.')
- let idx1 = stridx(line, '@')
- let idx2 = stridx(line, 'o')
- if idx1 != -1
- call cursor(0, idx1 + 1)
- else
- call cursor(0, idx2 + 1)
- endif
+ let target_n = line('.') + (distance * a:direction)
- let target_line = matchstr(getline("."), '\v\[[0-9]+\]')
- let target_num = matchstr(target_line, '\v[0-9]+')
- call s:GundoRenderPreview(target_num)
-endfunction
-
-function! s:GundoMoveDown()
- let start_line = getline('.')
- if line('.') + 2 >= line('$')
+ if target_n <= 4
+ call cursor(5, 0)
+ elseif target_n >= line('$')
call cursor(line('$') - 1, 0)
- elseif stridx(start_line, '[') == -1
- call cursor(line('.') + 1, 0)
else
- call cursor(line('.') + 2, 0)
+ call cursor(target_n, 0)
endif
let line = getline('.')
@@ -88,8 +73,10 @@
wincmd H
call s:GundoResizeBuffers(winnr())
nnoremap <script> <silent> <buffer> <CR> :call <sid>GundoRevert()<CR>
- nnoremap <script> <silent> <buffer> j :call <sid>GundoMoveDown()<CR>
- nnoremap <script> <silent> <buffer> k :call <sid>GundoMoveUp()<CR>
+ nnoremap <script> <silent> <buffer> j :call <sid>GundoMove(1)<CR>
+ nnoremap <script> <silent> <buffer> k :call <sid>GundoMove(-1)<CR>
+ nnoremap <script> <silent> <buffer> gg gg:call <sid>GundoMove(1)<CR>
+ nnoremap <script> <silent> <buffer> G G:call <sid>GundoMove(-1)<CR>
else
let existing_gundo_window = bufwinnr(existing_gundo_buffer)
@@ -608,7 +595,6 @@
vim.command('GundoOpenBuffer')
vim.command('setlocal modifiable')
- vim.command('normal ggdG')
vim.current.buffer[:] = (header + result)
vim.command('setlocal nomodifiable')
@@ -636,6 +622,9 @@
def GundoRenderPreview():
_goto_window_for_buffer(vim.eval('g:gundo_target_n'))
+ ut = vim.eval('undotree()')
+ entries = ut['entries']
+
root, nodes = make_nodes(entries)
current = changenr(nodes)