Skip to content

Commit

Permalink
fix(list): scrolling float preview for vim (#4647)
Browse files Browse the repository at this point in the history
Closes #4643

use `coc#float#scroll_win` to scroll float/popup window, same as hover
  • Loading branch information
fannheyward committed Aug 31, 2023
1 parent c5a7123 commit e4ffae5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion autoload/coc/list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,22 @@ function! coc#list#get_preview(...) abort
return -1
endfunction

function! coc#list#scroll_preview(dir) abort
function! coc#list#scroll_preview(dir, floatPreview) abort
let winid = coc#list#get_preview()
if winid == -1
return
endif
if a:floatPreview
let forward = a:dir ==# 'up' ? 0 : 1
let amount = 1
if s:is_vim
call coc#float#scroll_win(winid, forward, amount)
else
call timer_start(0, { -> coc#float#scroll_win(winid, forward, amount)})
endif
return
endif

if exists('*win_execute')
call win_execute(winid, "normal! ".(a:dir ==# 'up' ? "\<C-u>" : "\<C-d>"))
else
Expand Down
3 changes: 2 additions & 1 deletion src/list/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,10 @@ export default class Mappings {
}

private scrollPreview(dir: 'up' | 'down'): void {
const floatPreview = listConfiguration.get<boolean>('floatPreview', false)
let { nvim } = this
nvim.pauseNotification()
nvim.call('coc#list#scroll_preview', [dir], true)
nvim.call('coc#list#scroll_preview', [dir, floatPreview], true)
nvim.command('redraw', true)
nvim.resumeNotification(false, true)
}
Expand Down

0 comments on commit e4ffae5

Please sign in to comment.