# HG changeset patch # User Steve Losh # Date 1286924762 14400 # Node ID 920859982e84ed6dfd0903a4adf8ad2fadc5237e # Parent 7f1c71ef51419d5409cbf13b8f6cf8b59f6793df Refactor the movement into a single function. Feels good man. diff -r 7f1c71ef5141 -r 920859982e84 plugin/gundo.vim --- 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