Skip to content

Commit

Permalink
解决tab选择item时会对textchangedi -> textchangedp -> typingmatch
Browse files Browse the repository at this point in the history
有干扰的问题
  • Loading branch information
jayli committed Jan 12, 2024
1 parent 7a92193 commit a1f232a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion autoload/easycomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,7 @@ function! s:flush()
call s:CloseCompletionMenu()
endif
let s:easycomplete_start_pos = 0
let b:old_changedtick = 0
endfunction

function! s:ResetCompletedItem()
Expand Down Expand Up @@ -2346,7 +2347,11 @@ function! easycomplete#TextChangedI()
if g:env_is_nvim && easycomplete#pum#visible()
" TextChangedP
" call s:RememberCtx()
doautocmd <nomodeline> User easycomplete_pum_textchanged_p
if easycomplete#pum#InsertZizzing()
call easycomplete#pum#InsertAwake()
else
doautocmd <nomodeline> User easycomplete_pum_textchanged_p
endif
else
" TextChangedI
call easycomplete#tabnine#flush()
Expand Down Expand Up @@ -2474,6 +2479,7 @@ function! easycomplete#BufEnter()
endif
call timer_start(1600, { -> easycomplete#lint() })
endif
call s:flush()
endfunction

function! easycomplete#finish()
Expand Down
23 changes: 23 additions & 0 deletions autoload/easycomplete/pum.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ let s:default_scroll_bar_pot = {
let s:pum_window = 0
let s:pum_buffer = 0
let s:pum_direction = ""
" Insert word 的动作会触发 TextChangedI → TextChangedP → TypingMatch
" 这里要让 TextChangedI 躲过去,设置一个标志位
let s:pum_insert_word_timer = 0

" pum 高亮所需的临时样式 match id
let g:easycomplete_match_id = 0
Expand Down Expand Up @@ -424,6 +427,7 @@ function! easycomplete#pum#SetWordBySelecting()
let backing_count = cursor_left - pum_pos.pos[1] - 2
let oprator_str = repeat("\<bs>", backing_count)
let word = get(s:curr_items[s:selected_i - 1], "word", "")
call s:insert_zizz()
if !easycomplete#pum#CompleteCursored()
return oprator_str . get(s:original_ctx, "typing", "")
else
Expand Down Expand Up @@ -462,6 +466,25 @@ function! s:InsertWord(word)
execute 'noa set completeopt='.saved_completeopt
endfunction

function! s:insert_zizz()
if easycomplete#pum#InsertZizzing()
call timer_stop(s:pum_insert_word_timer)
endif
let s:pum_insert_word_timer = timer_start(500, { -> s:insert_awake() })
endfunction

function! s:insert_awake()
let s:pum_insert_word_timer = 0
endfunction

function! easycomplete#pum#InsertAwake()
call s:insert_awake()
endfunction

function! easycomplete#pum#InsertZizzing()
return s:pum_insert_word_timer > 0
endfunction

function! easycomplete#pum#select(line_index)
call s:select(a:line_index)
endfunction
Expand Down

0 comments on commit a1f232a

Please sign in to comment.