Improve find motion scroll

This commit is contained in:
haya14busa 2014-01-24 01:06:21 +09:00
parent 1124db2edd
commit ff15dabea7
2 changed files with 38 additions and 18 deletions

View File

@ -581,7 +581,8 @@ function! s:findMotion(num_strokes, direction) "{{{
let re = s:convertRegep(input) let re = s:convertRegep(input)
if g:EasyMotion_add_search_history && a:num_strokes == -1 if g:EasyMotion_add_search_history && a:num_strokes == -1
let @/ = re let @/ = re "For textobject: 'gn'
call histadd('search', re)
endif endif
return re return re

View File

@ -36,7 +36,7 @@ function! s:InputPrompt(message, input) "{{{
echon a:input echon a:input
endfunction "}}} endfunction "}}}
function! s:Cancell() " {{{ function! s:Cancell() " {{{
call EasyMotion#highlight#delete_highlight() call s:after_input()
keepjumps call setpos('.', s:save_orig_pos) keepjumps call setpos('.', s:save_orig_pos)
redraw redraw
echo 'EasyMotion: Cancelled' echo 'EasyMotion: Cancelled'
@ -67,7 +67,7 @@ function! s:before_input(num_strokes) "{{{
call EasyMotion#highlight#add_highlight('\%#', g:EasyMotion_hl_inc_cursor) call EasyMotion#highlight#add_highlight('\%#', g:EasyMotion_hl_inc_cursor)
endif endif
endfunction "}}} endfunction "}}}
function! s:after_input(num_strokes) "{{{ function! s:after_input() "{{{
call EasyMotion#highlight#delete_highlight() call EasyMotion#highlight#delete_highlight()
endfunction "}}} endfunction "}}}
function! s:should_use_smartcase(input) "{{{ function! s:should_use_smartcase(input) "{{{
@ -92,7 +92,7 @@ function! s:offscreen_search(re) "{{{
" Match " Match
keepjumps call setpos('.', pos) keepjumps call setpos('.', pos)
" Move cursor " Move cursor
if s:direction != 'b' if s:save_direction != 'b'
normal! zzH0 normal! zzH0
else else
normal! zzL0 normal! zzL0
@ -105,7 +105,7 @@ function! s:offscreen_search(re) "{{{
endif endif
endfunction "}}} endfunction "}}}
function! s:adjust_screen() "{{{ function! s:adjust_screen() "{{{
if s:direction != 'b' if s:save_direction != 'b'
" Forward " Forward
keepjumps call setpos('.', s:orig_line_start) keepjumps call setpos('.', s:orig_line_start)
normal! zt normal! zt
@ -115,10 +115,14 @@ function! s:adjust_screen() "{{{
normal! zb normal! zb
endif endif
endfunction "}}} endfunction "}}}
function! s:search_histories() "{{{
return map(range(&history), 'histget("search", v:val * -1)')
endfunction "}}}
function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{ function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
let previous_input = a:prev let previous_input = a:prev
let s:direction = a:direction == 1 ? 'b' : '' let s:save_direction = a:direction == 1 ? 'b' : ''
let s:direction = s:save_direction
let input = '' let input = ''
let prompt = s:getPromptMessage(a:num_strokes) let prompt = s:getPromptMessage(a:num_strokes)
@ -130,6 +134,10 @@ function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
call s:before_input(a:num_strokes) call s:before_input(a:num_strokes)
" let s:search_hist = s:search_histories()
let s:search_hist = []
let s:search_cnt = 0
while EasyMotion#helper#strchars(input) < a:num_strokes || while EasyMotion#helper#strchars(input) < a:num_strokes ||
\ a:num_strokes == -1 \ a:num_strokes == -1
if g:EasyMotion_show_prompt if g:EasyMotion_show_prompt
@ -140,6 +148,13 @@ function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
if EasyMotion#command_line#is_input("\<Esc>") if EasyMotion#command_line#is_input("\<Esc>")
" Cancel if Escape key pressed " Cancel if Escape key pressed
call s:Cancell() | let input = '' | break call s:Cancell() | let input = '' | break
elseif EasyMotion#command_line#is_input("\<CR>")
if len(input) == 0
let input = previous_input | break
endif
break
elseif EasyMotion#command_line#is_input("\<C-j>")
break
elseif EasyMotion#command_line#is_input("\<C-c>") elseif EasyMotion#command_line#is_input("\<C-c>")
" Cancel " Cancel
call s:Cancell() | let input = '' | break call s:Cancell() | let input = '' | break
@ -164,32 +179,36 @@ function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
elseif EasyMotion#command_line#is_input("\<C-w>") elseif EasyMotion#command_line#is_input("\<C-w>")
" Delete word " Delete word
let input = matchstr(input, '^\zs.\{-}\ze\(\(\w*\)\|\(.\)\)$') let input = matchstr(input, '^\zs.\{-}\ze\(\(\w*\)\|\(.\)\)$')
elseif EasyMotion#command_line#is_input("\<C-p>") elseif EasyMotion#command_line#is_input("\<C-p>") || EasyMotion#command_line#is_input("\<C-n>")
let input = previous_input if s:search_cnt == 0 && empty(s:search_hist)
elseif EasyMotion#command_line#is_input("\<C-n>") let cmdline = '^' . input
let input = '' let s:search_hist = filter(s:search_histories(), 'v:val =~ cmdline')
elseif EasyMotion#command_line#is_input("\<CR>")
if len(input) == 0
let input = previous_input | break
endif endif
break if EasyMotion#command_line#is_input("\<C-n>")
elseif EasyMotion#command_line#is_input("\<C-j>") let s:search_cnt = max([s:search_cnt - 1, 0])
break endif
if EasyMotion#command_line#is_input("\<C-p>")
let s:search_cnt = min([s:search_cnt + 1, len(s:search_hist)])
endif
let input = get(s:search_hist, s:search_cnt, input)
elseif EasyMotion#command_line#is_input("\<Tab>") elseif EasyMotion#command_line#is_input("\<Tab>")
exec "normal! \<C-f>" exec "normal! \<C-f>"
let s:orig_pos = getpos('.') let s:orig_pos = getpos('.')
let s:orig_line_start = getpos('w0') let s:orig_line_start = getpos('w0')
let s:orig_line_end = getpos('w$') let s:orig_line_end = getpos('w$')
let s:direction = ''
elseif EasyMotion#command_line#is_input("\<S-Tab>") elseif EasyMotion#command_line#is_input("\<S-Tab>")
exec "normal! \<C-b>" exec "normal! \<C-b>"
let s:orig_pos = getpos('.') let s:orig_pos = getpos('.')
let s:orig_line_start = getpos('w0') let s:orig_line_start = getpos('w0')
let s:orig_line_end = getpos('w$') let s:orig_line_end = getpos('w$')
let s:direction = 'b'
elseif EasyMotion#command_line#is_input("\<C-o>") elseif EasyMotion#command_line#is_input("\<C-o>")
call setpos('.', s:save_orig_pos) keepjumps call setpos('.', s:save_orig_pos)
let s:orig_pos = s:save_orig_pos let s:orig_pos = s:save_orig_pos
let s:orig_line_start = getpos('w0') let s:orig_line_start = getpos('w0')
let s:orig_line_end = getpos('w$') let s:orig_line_end = getpos('w$')
let s:direction = ''
elseif EasyMotion#command_line#is_input("\<C-z>") elseif EasyMotion#command_line#is_input("\<C-z>")
normal! zR normal! zR
elseif char2nr(s:char) == 128 || char2nr(s:char) < 27 elseif char2nr(s:char) == 128 || char2nr(s:char) < 27
@ -216,7 +235,7 @@ function! EasyMotion#command_line#GetInput(num_strokes, prev, direction) "{{{
endif endif
"}}} "}}}
endwhile endwhile
call s:after_input(a:num_strokes) call s:after_input()
return input return input
endfunction "}}} endfunction "}}}
function! EasyMotion#command_line#char() "{{{ function! EasyMotion#command_line#char() "{{{