1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-12 17:55:41 +08:00

Fix flygrep history completion (#3659)

This commit is contained in:
Wang Shidong 2020-07-25 22:59:40 +08:00 committed by GitHub
parent 21bbc714ee
commit 44b3a99d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -679,8 +679,6 @@ function! s:previous_match_history() abort
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)
@ -693,8 +691,6 @@ function! s:next_match_history() abort
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)
@ -704,14 +700,21 @@ endfunction
function! s:complete_input_history(str,num) abort
let results = filter(copy(s:grep_history), "v:val =~# '^' . a:str")
if a:num[0] - a:num[1] == 0
return a:str
elseif len(results) > 0
let index = ((len(results) - 1) - a:num[0] + a:num[1]) % len(results)
return results[index]
if !empty(results) && results[-1] !=# a:str
let complete_items = results + [a:str]
elseif empty(results)
let complete_items = [a:str]
else
return a:str
let complete_items = results
endif
" 5 0 6
let patch = (a:num[0] - a:num[1]) % len(complete_items)
if patch >= 0
let index = len(complete_items) - 1 - patch
else
let index = abs(patch) - 1
endif
return complete_items[index]
endfunction
let s:MPT._function_key = {