Created
January 13, 2021 05:36
-
-
Save Gee19/20a4280bc319cb76d00b398585268234 to your computer and use it in GitHub Desktop.
Scroll floating win in insert mode (creds to @oblitum)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! FloatScroll(forward) abort | |
let float = coc#util#get_float() | |
if !float | return '' | endif | |
let buf = nvim_win_get_buf(float) | |
let buf_height = nvim_buf_line_count(buf) | |
let win_height = nvim_win_get_height(float) | |
if buf_height < win_height | return '' | endif | |
let pos = nvim_win_get_cursor(float) | |
if a:forward | |
if pos[0] == 1 | |
let pos[0] += 3 * win_height / 4 | |
elseif pos[0] + win_height / 2 + 1 < buf_height | |
let pos[0] += win_height / 2 + 1 | |
else | |
let pos[0] = buf_height | |
endif | |
else | |
if pos[0] == buf_height | |
let pos[0] -= 3 * win_height / 4 | |
elseif pos[0] - win_height / 2 + 1 > 1 | |
let pos[0] -= win_height / 2 + 1 | |
else | |
let pos[0] = 1 | |
endif | |
endif | |
call nvim_win_set_cursor(float, pos) | |
return '' | |
endfunction | |
inoremap <silent><expr> <down> coc#util#has_float() ? FloatScroll(1) : "\<down>" | |
inoremap <silent><expr> <up> coc#util#has_float() ? FloatScroll(0) : "\<up>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment