1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 09:20:06 +08:00

Merge pull request #1592 from wsdjeg/flygrep_history

Add histroy support in flygrep
This commit is contained in:
Wang Shidong 2018-04-01 20:37:44 +08:00 committed by GitHub
commit 84a7df5a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,8 @@ let [
\ ] = SpaceVim#mapping#search#default_tool()
let s:grep_timer_id = 0
let s:grepid = 0
let s:grep_history = []
let s:complete_input_history_num = [0,0]
" }}}
" grep local funcs:{{{
@ -247,6 +249,7 @@ function! s:previous_item() abort
endfunction
function! s:open_item() abort
call add(s:grep_history, s:grep_expr)
let s:MPT._handle_fly = function('s:flygrep')
if getline('.') !=# ''
if s:grepid != 0
@ -329,7 +332,46 @@ function! s:toggle_expr_mode() abort
call s:MPT._handle_fly(s:MPT._prompt.begin . s:MPT._prompt.cursor .s:MPT._prompt.end)
endfunction
let s:complete_input_history_base = ''
function! s:previous_match_history() abort
if s:complete_input_history_num == [0,0]
let s:complete_input_history_base = s:MPT._prompt.begin
let s:MPT._prompt.cursor = ''
let s:MPT._prompt.end = ''
else
let s:MPT._prompt.begin = s:complete_input_history_base
endif
let s:complete_input_history_num[0] += 1
let s:MPT._prompt.begin = s:complete_input_history(s:complete_input_history_base, s:complete_input_history_num)
normal! "_ggdG
call s:MPT._handle_fly(s:MPT._prompt.begin . s:MPT._prompt.cursor .s:MPT._prompt.end)
endfunction
function! s:next_match_history() abort
if s:complete_input_history_num == [0,0]
let s:complete_input_history_base = s:MPT._prompt.begin
let s:MPT._prompt.cursor = ''
let s:MPT._prompt.end = ''
else
let s:MPT._prompt.begin = s:complete_input_history_base
endif
let s:complete_input_history_num[1] += 1
let s:MPT._prompt.begin = s:complete_input_history(s:complete_input_history_base, s:complete_input_history_num)
normal! "_ggdG
call s:MPT._handle_fly(s:MPT._prompt.begin . s:MPT._prompt.cursor .s:MPT._prompt.end)
endfunction
function! s:complete_input_history(str,num) abort
let results = filter(copy(s:grep_history), "v:val =~# '^' . a:str")
if len(results) > 0
call add(results, a:str)
let index = ((len(results) - 1) - a:num[0] + a:num[1]) % len(results)
return results[index]
else
return a:str
endif
endfunction
let s:MPT._function_key = {
\ "\<Tab>" : function('s:next_item'),
\ "\<C-j>" : function('s:next_item'),
@ -344,6 +386,8 @@ let s:MPT._function_key = {
\ "\<C-r>" : function('s:start_replace'),
\ "\<C-p>" : function('s:toggle_preview'),
\ "\<C-e>" : function('s:toggle_expr_mode'),
\ "\<Up>" : function('s:previous_match_history'),
\ "\<Down>" : function('s:next_match_history'),
\ }
if has('nvim')
@ -410,7 +454,7 @@ function! SpaceVim#plugins#flygrep#lineNr() abort
endif
endfunction
function! SpaceVim#plugins#flygrep#mode()
function! SpaceVim#plugins#flygrep#mode() abort
return s:grep_mode . (empty(s:mode) ? '' : '(' . s:mode . ')')
endfunction