Skip to content

Commit

Permalink
bugfix for #275
Browse files Browse the repository at this point in the history
  • Loading branch information
jayli committed Dec 12, 2023
1 parent 4354697 commit 587984e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
14 changes: 9 additions & 5 deletions autoload/easycomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ function! s:SecondCompleteRendering(start_pos, result)
if g:env_is_iterm
call s:StopAsyncRun()
if len(g:easycomplete_stunt_menuitems) < 40
call s:AsyncRun(function('s:complete'), [a:start_pos, a:result], 0)
silent noa call s:AsyncRun(function('s:complete'), [a:start_pos, a:result], 0)
else
call s:StopAsyncRun()
call s:AsyncRun(function('easycomplete#_complete'), [a:start_pos, a:result], 0)
silent noa call s:AsyncRun(function('easycomplete#_complete'), [a:start_pos, a:result], 0)
endif
else
call s:StopAsyncRun()
Expand Down Expand Up @@ -1074,9 +1073,7 @@ function! s:ShowCompleteInfoWithoutTimer()
if type(info) == type("")
let info = [info]
endif
" call s:StopAsyncRun()
call s:ShowCompleteInfo(info)
" call s:AsyncRun(function('s:ShowCompleteInfo'), [info], 100)
endif
endfunction

Expand Down Expand Up @@ -1558,7 +1555,14 @@ function! easycomplete#_complete(start, items)
\ 'candidates': a:items,
\ }
if mode() =~# 'i' && &paste != 1
let should_fire_pum_show = v:false
if !pumvisible() && !empty(a:item)
let should_fire_pum_show = v:true
endif
silent! noa call feedkeys("\<Plug>EasycompleteRefresh", 'i')
if should_fire_pum_show
doautocmd <nomodeline> User easycomplete_pum_show
endif
endif
endfunction

Expand Down
38 changes: 29 additions & 9 deletions autoload/easycomplete/popup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ let s:buf = {
function! easycomplete#popup#MenuPopupChanged(info)
if empty(v:event) && easycomplete#FirstSelectedWithOptDefaultSelected()
" 如果默认选中第一项
let s:item = easycomplete#GetCursordItem()
let curr_item = easycomplete#GetCursordItem()
" if !empty(s:GetMenuInfoWinid()) && s:SamePositionAsLastTime() && easycomplete#util#SameItem(s:item, curr_item)
" return
" endif
let s:item = deepcopy(curr_item)
call easycomplete#popup#DoPopup(a:info, 1)
else
if empty(v:event) && empty(g:easycomplete_completechanged_event) | return | endif
Expand All @@ -66,6 +70,30 @@ function! easycomplete#popup#MenuPopupChanged(info)
let s:info = a:info
endfunction

function! s:GetMenuInfoWinid()
return g:easycomplete_popup_win["popup"]
endfunction

function! s:SamePositionAsLastTime()
let pum_pos = pum_getpos()
if !exists("s:easycomplete_pum_pos")
let s:easycomplete_pum_pos = deepcopy(pum_pos)
return v:false
endif
" if !pumvisible()
" unlet s:easycomplete_pum_pos
" return v:false
" endif
if pum_pos.height == s:easycomplete_pum_pos.height &&
\ pum_pos.width == s:easycomplete_pum_pos.width &&
\ pum_pos.col == s:easycomplete_pum_pos.col &&
\ pum_pos.row == s:easycomplete_pum_pos.row
return v:true
else
return v:false
endif
endfunction

function! easycomplete#popup#CompleteDone()
let s:item = copy(v:completed_item)
call easycomplete#popup#close("popup")
Expand Down Expand Up @@ -438,27 +466,19 @@ function! s:NVimShow(opt, windowtype, float_type)
else
let hl = 'Pmenu'
endif
" if !empty(get(g:easycomplete_popup_win, a:windowtype, ""))
" let a:opt.win = get(g:easycomplete_popup_win, a:windowtype, "")
" endif
let l:filetype = &filetype == "lua" ? "help" : &filetype
let hl_str = 'Normal:' . hl . ',NormalNC:' . hl
let winargs = [s:buf[a:windowtype], 0, a:opt]
unlet winargs[2].filetype
silent let winid = nvim_open_win(s:buf[a:windowtype], v:false, winargs[2])
call nvim_set_option_value('winhl', hl_str, {'win': winid})
let g:easycomplete_popup_win[a:windowtype] = winid
if exists('*nvim_win_set_config')
call nvim_win_set_config(g:easycomplete_popup_win[a:windowtype], {
\ 'cursorline': v:false,
\ 'colorcolumn': '',
\ })
else
call nvim_win_set_option(g:easycomplete_popup_win[a:windowtype], 'relativenumber', v:false)
call nvim_win_set_option(g:easycomplete_popup_win[a:windowtype], 'cursorline', v:false)
call nvim_win_set_option(g:easycomplete_popup_win[a:windowtype], 'colorcolumn', '')
endif
call nvim_win_set_var(g:easycomplete_popup_win[a:windowtype], 'syntax', 'off')
if has('nvim-0.5.0')
call setwinvar(g:easycomplete_popup_win[a:windowtype], '&scrolloff', 0)
call setwinvar(g:easycomplete_popup_win[a:windowtype], '&spell', 0)
Expand Down
18 changes: 11 additions & 7 deletions autoload/easycomplete/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,24 @@ function! s:HasItem(list,item)
endfunction

function! s:SameItem(item1,item2)
let item1 = a:item1
let item2 = a:item2
if get(item1, "word") ==# get(item2, "word")
\ && get(item1, "menu") ==# get(item2, "menu")
\ && get(item1, "kind") ==# get(item2, "kind")
\ && get(item1, "abbr") ==# get(item2, "abbr")
\ && get(item1, "info") ==# get(item2, "info")
let l:item1 = a:item1
let l:item2 = a:item2
if get(l:item1, "word") ==# get(l:item2, "word")
\ && get(l:item1, "menu") ==# get(l:item2, "menu")
\ && get(l:item1, "kind") ==# get(l:item2, "kind")
\ && get(l:item1, "abbr") ==# get(l:item2, "abbr")
\ && get(l:item1, "info") ==# get(l:item2, "info")
return v:true
else
return v:false
endif
endfunction
" }}}

function! easycomplete#util#SameItem(item1, item2) " {{{
return s:SameItem(a:item1, a:item2)
endfunction " }}}

" goto location {{{
function! easycomplete#util#location(path, line, col, ...) abort
normal! m'
Expand Down

0 comments on commit 587984e

Please sign in to comment.