From 8dba1d20bac8de81bceaf7011150804a4f5a52a1 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Tue, 23 May 2023 09:31:54 +0800 Subject: [PATCH] fix(list): scrolling float preview for vim Closes #4643 use `coc#float#scroll_win` to scroll float/popup window, same as hover --- autoload/coc/list.vim | 13 ++++++++++++- src/list/mappings.ts | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/autoload/coc/list.vim b/autoload/coc/list.vim index fdf33bed939..afd4952e777 100644 --- a/autoload/coc/list.vim +++ b/autoload/coc/list.vim @@ -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' ? "\" : "\")) else diff --git a/src/list/mappings.ts b/src/list/mappings.ts index 9f0ed3f686b..cb0e2c5c91f 100644 --- a/src/list/mappings.ts +++ b/src/list/mappings.ts @@ -301,9 +301,10 @@ export default class Mappings { } private scrollPreview(dir: 'up' | 'down'): void { + const floatPreview = listConfiguration.get('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) }