[vim] Move and resize popup window when detecting VimResized event
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #4778
authored by Vulcalien · committed by Junegunn Choi · parent 1ad7c61 · Browse files · 1 file·+57 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+57 added−25 removed
- other:+57 added−25 removed
Provenance
- Commit
780a624- Tree
904bc23- Author
Vulcalien <vulcalien@vulcalien.net>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
1ad7c61
1 file changed+57 added−25 removed
modified:plugin/fzf.vim+57 added-25 removed
894 unmodified lines895 endif896 endif897 endfunction898 function! fzf.on_exit(id, code, ...)899+ silent! autocmd! fzf_popup_resize900 if s:getpos() == self.ppos " {'window': 'enew'}901 for [opt, val] in items(self.winopts)902 execute 'let' opt '=' val903 endfor119 unmodified lines1023 endif1024 endfunction1025 1026 if has('nvim')1026- function s:create_popup(opts) abort1027+ function! s:create_popup() abort1028+ let opts = s:popup_bounds()1029+ let opts = extend({'relative': 'editor', 'style': 'minimal'}, opts)1030+1031 let buf = nvim_create_buf(v:false, v:true)1028- let opts = extend({'relative': 'editor', 'style': 'minimal'}, a:opts)1029- let win = nvim_open_win(buf, v:true, opts)1030- call setwinvar(win, '&colorcolumn', '')1032+ let s:popup_id = nvim_open_win(buf, v:true, opts)1033+ call setwinvar(s:popup_id, '&colorcolumn', '')1034 1035 " Colors1036 try1034- call setwinvar(win, '&winhighlight', 'Pmenu:,Normal:Normal')1037+ call setwinvar(s:popup_id, '&winhighlight', 'Pmenu:,Normal:Normal')1038 let rules = get(g:, 'fzf_colors', {})1039 if has_key(rules, 'bg')1040 let color = call('s:get_color', rules.bg)1041 if len(color)1042 let ns = nvim_create_namespace('fzf_popup')1043 let hl = nvim_set_hl(ns, 'Normal',1044 \ &termguicolors ? { 'bg': color } : { 'ctermbg': str2nr(color) })1042- call nvim_win_set_hl_ns(win, ns)1045+ call nvim_win_set_hl_ns(s:popup_id, ns)1046 endif1047 endif1048 catch1049 endtry1050 return buf1051 endfunction1052+1053+ function! s:resize_popup() abort1054+ if !exists('s:popup_id') || !nvim_win_is_valid(s:popup_id)1055+ return1056+ endif1057+ let opts = s:popup_bounds()1058+ let opts = extend({'relative': 'editor'}, opts)1059+ call nvim_win_set_config(s:popup_id, opts)1060+ endfunction1061 else1050- function! s:create_popup(opts) abort1051- let s:popup_create = {buf -> popup_create(buf, #{1052- \ line: a:opts.row,1053- \ col: a:opts.col,1054- \ minwidth: a:opts.width,1055- \ maxwidth: a:opts.width,1056- \ minheight: a:opts.height,1057- \ maxheight: a:opts.height,1058- \ zindex: 1000,1059- \ })}1062+ function! s:create_popup() abort1063+ function! s:popup_create(buf)1064+ let s:popup_id = popup_create(a:buf, #{zindex: 1000})1065+ call s:resize_popup()1066+ endfunction1067 autocmd TerminalOpen * ++once call s:popup_create(str2nr(expand('<abuf>')))1068 endfunction1069+1070+ function! s:resize_popup() abort1071+ if !exists('s:popup_id') || empty(popup_getpos(s:popup_id))1072+ return1073+ endif1074+ let opts = s:popup_bounds()1075+ call popup_move(s:popup_id, {1076+ \ 'line': opts.row,1077+ \ 'col': opts.col,1078+ \ 'minwidth': opts.width,1079+ \ 'maxwidth': opts.width,1080+ \ 'minheight': opts.height,1081+ \ 'maxheight': opts.height,1082+ \ })1083+ endfunction1084 endif1085 1064-function! s:popup(opts) abort1065- let xoffset = get(a:opts, 'xoffset', 0.5)1066- let yoffset = get(a:opts, 'yoffset', 0.5)1067- let relative = get(a:opts, 'relative', 0)1086+function! s:popup_bounds() abort1087+ let opts = s:popup_opts1088 1089+ let xoffset = get(opts, 'xoffset', 0.5)1090+ let yoffset = get(opts, 'yoffset', 0.5)1091+ let relative = get(opts, 'relative', 0)1092+1093 " Use current window size for positioning relatively positioned popups1094 let columns = relative ? winwidth(0) : &columns1095 let lines = relative ? winheight(0) : (&lines - has('nvim'))1096 1097 " Size and position1074- let width = min([max([8, a:opts.width > 1 ? a:opts.width : float2nr(columns * a:opts.width)]), columns])1075- let height = min([max([4, a:opts.height > 1 ? a:opts.height : float2nr(lines * a:opts.height)]), lines])1098+ let width = min([max([8, opts.width > 1 ? opts.width : float2nr(columns * opts.width)]), columns])1099+ let height = min([max([4, opts.height > 1 ? opts.height : float2nr(lines * opts.height)]), lines])1100 let row = float2nr(yoffset * (lines - height)) + (relative ? win_screenpos(0)[0] - 1 : 0)1101 let col = float2nr(xoffset * (columns - width)) + (relative ? win_screenpos(0)[1] - 1 : 0)1102 1103 " Managing the differences1 unmodified line1105 let col = min([max([0, col]), &columns - width])1106 let row += !has('nvim')1107 let col += !has('nvim')1108 1085- call s:create_popup({1086- \ 'row': row, 'col': col, 'width': width, 'height': height1087- \ })1109+ return { 'row': row, 'col': col, 'width': width, 'height': height }1110 endfunction1111 1112+function! s:popup(opts) abort1113+ let s:popup_opts = a:opts1114+ call s:create_popup()1115+1116+ augroup fzf_popup_resize1117+ autocmd!1118+ autocmd VimResized * call s:resize_popup()1119+ augroup END1120+endfunction1121+1122 let s:default_action = {1123 \ 'ctrl-t': 'tab split',1124 \ 'ctrl-x': 'split',1125 \ 'ctrl-v': 'vsplit' }32 unmodified lines