Vim: make :SignifyPreviewHunk use popup window
References https://github.com/mhinz/vim-signify/pull/302
This commit is contained in:
parent
2673d732dd
commit
469ae5c9f7
@ -306,20 +306,20 @@ function! s:preview_hunk(_sy, vcs, diff) abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists('*nvim_open_win')
|
if sy#util#popup_create(hunk)
|
||||||
call sy#util#renderPopup(hunk)
|
return
|
||||||
else
|
|
||||||
silent! wincmd P
|
|
||||||
if !&previewwindow
|
|
||||||
noautocmd botright new
|
|
||||||
endif
|
|
||||||
call setline(1, hunk)
|
|
||||||
silent! %foldopen!
|
|
||||||
setlocal previewwindow filetype=diff buftype=nofile bufhidden=delete
|
|
||||||
" With :noautocmd wincmd p, the first line of the preview window would show
|
|
||||||
" the 'cursorline', although it's not focused. Use feedkeys() instead.
|
|
||||||
noautocmd call feedkeys("\<c-w>p", 'nt')
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
silent! wincmd P
|
||||||
|
if !&previewwindow
|
||||||
|
noautocmd botright new
|
||||||
|
endif
|
||||||
|
call setline(1, hunk)
|
||||||
|
silent! %foldopen!
|
||||||
|
setlocal previewwindow filetype=diff buftype=nofile bufhidden=delete
|
||||||
|
" With :noautocmd wincmd p, the first line of the preview window would show
|
||||||
|
" the 'cursorline', although it's not focused. Use feedkeys() instead.
|
||||||
|
noautocmd call feedkeys("\<c-w>p", 'nt')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_cur_line_in_hunk(hunkline) abort
|
function! s:is_cur_line_in_hunk(hunkline) abort
|
||||||
|
@ -108,41 +108,54 @@ function! sy#util#execute(cmd) abort
|
|||||||
return output
|
return output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:window = 0
|
let s:popup_window = 0
|
||||||
|
|
||||||
function! sy#util#closePopup()
|
function! sy#util#popup_close() abort
|
||||||
if s:window
|
if s:popup_window
|
||||||
let id = win_id2win(s:window)
|
call nvim_win_close(s:popup_window, 1)
|
||||||
if id > 0
|
let s:popup_window = 0
|
||||||
execute id . 'close!'
|
|
||||||
endif
|
|
||||||
let s:window = 0
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! sy#util#renderPopup(input, ...)
|
function! sy#util#popup_create(hunkdiff, ...) abort
|
||||||
call sy#util#closePopup()
|
|
||||||
let s:buf = nvim_create_buf(0, 1)
|
|
||||||
call nvim_buf_set_option(s:buf, 'syntax', 'diff')
|
|
||||||
let max_width = 100
|
let max_width = 100
|
||||||
let max_height = 16
|
let max_height = 16
|
||||||
let width = max(map(copy(a:input), {_, v -> len(v)})) + 1
|
let width = max(map(copy(a:hunkdiff), {_, v -> len(v)})) + 1
|
||||||
let width = (width > max_width) ? max_width : width
|
let width = (width > max_width) ? max_width : width
|
||||||
let height = len(a:input)
|
let height = len(a:hunkdiff)
|
||||||
let height = (height > max_height) ? max_height : height
|
let height = (height > max_height) ? max_height : height
|
||||||
call nvim_buf_set_lines(s:buf, 0, -1, 0, a:input)
|
|
||||||
let s:window = call('nvim_open_win', [s:buf, v:false, {
|
if exists('*nvim_open_win')
|
||||||
|
call sy#util#popup_close()
|
||||||
|
let buf = nvim_create_buf(0, 1)
|
||||||
|
call nvim_buf_set_option(buf, 'syntax', 'diff')
|
||||||
|
call nvim_buf_set_lines(buf, 0, -1, 0, a:hunkdiff)
|
||||||
|
let s:popup_window = call('nvim_open_win', [buf, v:false, {
|
||||||
\ 'relative': 'cursor',
|
\ 'relative': 'cursor',
|
||||||
\ 'row': 0,
|
\ 'row': 0,
|
||||||
\ 'col': 0,
|
\ 'col': 0,
|
||||||
\ 'width': width,
|
\ 'width': width,
|
||||||
\ 'height': height,
|
\ 'height': height,
|
||||||
\ }])
|
\ }])
|
||||||
call nvim_win_set_option(s:window, 'cursorline', v:false)
|
call nvim_win_set_option(s:popup_window, 'cursorline', v:false)
|
||||||
call nvim_win_set_option(s:window, 'foldenable', v:false)
|
call nvim_win_set_option(s:popup_window, 'foldenable', v:false)
|
||||||
call nvim_win_set_option(s:window, 'number', v:false)
|
call nvim_win_set_option(s:popup_window, 'number', v:false)
|
||||||
call nvim_win_set_option(s:window, 'relativenumber', v:false)
|
call nvim_win_set_option(s:popup_window, 'relativenumber', v:false)
|
||||||
call nvim_win_set_option(s:window, 'statusline', '')
|
call nvim_win_set_option(s:popup_window, 'wrap', v:true)
|
||||||
call nvim_win_set_option(s:window, 'wrap', v:true)
|
autocmd CursorMoved * ++once call sy#util#popup_close()
|
||||||
autocmd CursorMoved * call sy#util#closePopup()
|
elseif exists('*popup_create')
|
||||||
|
let s:popup_window = popup_create(a:hunkdiff, {
|
||||||
|
\ 'line': 'cursor',
|
||||||
|
\ 'col': 'cursor',
|
||||||
|
\ 'maxwidth': width,
|
||||||
|
\ 'maxheight': height,
|
||||||
|
\ 'moved': 'any',
|
||||||
|
\ 'zindex': 1000,
|
||||||
|
\ })
|
||||||
|
call setbufvar(winbufnr(s:popup_window), '&filetype', 'diff')
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 1
|
||||||
endfunction
|
endfunction
|
Loading…
Reference in New Issue
Block a user