Update coc.nvim
This commit is contained in:
parent
8f2091a3e4
commit
6bd73b104c
7 changed files with 444 additions and 248 deletions
|
@ -2,9 +2,11 @@ scriptencoding utf-8
|
|||
let s:is_vim = !has('nvim')
|
||||
let s:root = expand('<sfile>:h:h:h')
|
||||
let s:prompt_win_bufnr = 0
|
||||
let s:list_win_bufnr = 0
|
||||
let s:prompt_win_width = get(g:, 'coc_prompt_win_width', 32)
|
||||
let s:float_supported = exists('*nvim_open_win') || has('patch-8.1.1719')
|
||||
let s:frames = ['· ', '·· ', '···', ' ··', ' ·', ' ']
|
||||
let s:sign_group = 'PopUpCocDialog'
|
||||
|
||||
" Float window aside pum
|
||||
function! coc#dialog#create_pum_float(winid, bufnr, lines, config) abort
|
||||
|
@ -109,12 +111,13 @@ function! coc#dialog#create_prompt_win(title, default, opts) abort
|
|||
execute 'hi link CocPopupTerminal '.get(a:opts, 'highlight', 'CocFloating')
|
||||
let node = expand(get(g:, 'coc_node_path', 'node'))
|
||||
let bufnr = term_start([node, s:root . '/bin/prompt.js', a:default], {
|
||||
\ 'term_rows': 1,
|
||||
\ 'term_highlight': 'CocPopupTerminal',
|
||||
\ 'hidden': 1,
|
||||
\ 'term_finish': 'close'
|
||||
\ })
|
||||
call term_setapi(bufnr, 'Coc')
|
||||
call timer_start(100, { -> s:check_term_buffer(a:default, bufnr)})
|
||||
call setbufvar(bufnr, 'current', type(a:default) == v:t_string ? a:default : '')
|
||||
endif
|
||||
let config = s:get_prompt_dimension(a:title, a:default, a:opts)
|
||||
let res = coc#float#create_float_win(0, bufnr, extend(config, {
|
||||
|
@ -138,24 +141,65 @@ function! coc#dialog#create_prompt_win(title, default, opts) abort
|
|||
call nvim_set_current_win(winid)
|
||||
inoremap <buffer> <C-a> <Home>
|
||||
inoremap <buffer><expr><C-e> pumvisible() ? "\<C-e>" : "\<End>"
|
||||
exe 'imap <silent><buffer> <esc> <esc><esc>'
|
||||
exe 'imap <silent><nowait><buffer> <esc> <esc><esc>'
|
||||
exe 'nnoremap <silent><buffer> <esc> :call coc#float#close('.winid.')<CR>'
|
||||
exe 'inoremap <silent><expr><nowait><buffer> <cr> "\<C-r>=coc#dialog#prompt_insert(getline(''.''))\<cr>\<esc>"'
|
||||
if get(a:opts, 'list', 0)
|
||||
for key in ['<C-j>', '<C-k>', '<C-n>', '<C-p>', '<up>', '<down>', '<C-f>', '<C-b>', '<C-space>']
|
||||
" Can't use < in remap
|
||||
let escaped = key ==# '<C-space>' ? "C-@" : strcharpart(key, 1, strchars(key) - 2)
|
||||
exe 'inoremap <nowait><buffer> '.key.' <Cmd>call coc#rpc#notify("PromptKeyPress", ['.bufnr.', "'.escaped.'"])<CR>'
|
||||
endfor
|
||||
endif
|
||||
call feedkeys('A', 'in')
|
||||
endif
|
||||
call coc#util#do_autocmd('CocOpenFloatPrompt')
|
||||
if s:is_vim
|
||||
let pos = popup_getpos(winid)
|
||||
" width height row col
|
||||
let dimension = [pos['width'], pos['height'], pos['line'], pos['col'] - 1]
|
||||
let dimension = [pos['width'], pos['height'], pos['line'] - 1, pos['col'] - 1]
|
||||
else
|
||||
let id = coc#float#get_related(winid, 'border')
|
||||
if !has('nvim-0.6.0')
|
||||
redraw
|
||||
endif
|
||||
let pos = nvim_win_get_position(id)
|
||||
let dimension = [nvim_win_get_width(id), nvim_win_get_height(id), pos[0], pos[1]]
|
||||
endif
|
||||
return [bufnr, winid, dimension]
|
||||
endfunction
|
||||
|
||||
" Create list window under target window
|
||||
function! coc#dialog#create_list(target, dimension, opts) abort
|
||||
let maxHeight = get(a:opts, 'maxHeight', 10)
|
||||
let height = max([1, len(get(a:opts, 'lines', []))])
|
||||
let height = min([maxHeight, height, &lines - &cmdheight - 1 - a:dimension['row'] + a:dimension['height']])
|
||||
let chars = get(a:opts, 'rounded', 1) ? ['╯', '╰'] : ['┘', '└']
|
||||
let config = extend(copy(a:opts), {
|
||||
\ 'relative': 'editor',
|
||||
\ 'row': a:dimension['row'] + a:dimension['height'],
|
||||
\ 'col': a:dimension['col'],
|
||||
\ 'width': a:dimension['width'] - 2,
|
||||
\ 'height': height,
|
||||
\ 'border': [1, 1, 1, 1],
|
||||
\ 'scrollinside': 1,
|
||||
\ 'borderchars': extend(['─', '│', '─', '│', '├', '┤'], chars)
|
||||
\ })
|
||||
let bufnr = 0
|
||||
let result = coc#float#create_float_win(0, s:list_win_bufnr, config)
|
||||
if empty(result)
|
||||
return
|
||||
endif
|
||||
let winid = result[0]
|
||||
call coc#float#add_related(winid, a:target)
|
||||
call setwinvar(winid, 'auto_height', get(a:opts, 'autoHeight', 1))
|
||||
call setwinvar(winid, 'max_height', maxHeight)
|
||||
call setwinvar(winid, 'target_winid', a:target)
|
||||
call setwinvar(winid, 'kind', 'list')
|
||||
call coc#dialog#check_scroll_vim(a:target)
|
||||
return result
|
||||
endfunction
|
||||
|
||||
" Create menu picker for pick single item
|
||||
function! coc#dialog#create_menu(lines, config) abort
|
||||
call s:close_auto_hide_wins()
|
||||
|
@ -174,9 +218,6 @@ function! coc#dialog#create_menu(lines, config) abort
|
|||
\ 'highlights': get(a:config, 'highlights', []),
|
||||
\ 'relative': relative,
|
||||
\ }
|
||||
if s:is_vim
|
||||
let opts['cursorline'] = 1
|
||||
endif
|
||||
if relative ==# 'editor'
|
||||
let dimension = coc#dialog#get_config_editor(a:lines, opts)
|
||||
else
|
||||
|
@ -188,11 +229,10 @@ function! coc#dialog#create_menu(lines, config) abort
|
|||
return
|
||||
endif
|
||||
let s:prompt_win_bufnr = res[1]
|
||||
call s:place_sign(s:prompt_win_bufnr, 1)
|
||||
redraw
|
||||
if has('nvim')
|
||||
call coc#float#nvim_scrollbar(res[0])
|
||||
execute 'sign unplace 6 buffer='.s:prompt_win_bufnr
|
||||
execute 'sign place 6 line=1 name=CocCurrentLine buffer='.s:prompt_win_bufnr
|
||||
endif
|
||||
return res
|
||||
endfunction
|
||||
|
@ -217,19 +257,16 @@ function! coc#dialog#create_dialog(lines, config) abort
|
|||
\ 'borderhighlight': borderhighlight,
|
||||
\ 'getchar': get(a:config, 'getchar', 0)
|
||||
\ }
|
||||
if get(a:config, 'cursorline', 0)
|
||||
let opts['cursorline'] = 1
|
||||
endif
|
||||
call extend(opts, coc#dialog#get_config_editor(a:lines, a:config))
|
||||
let bufnr = coc#float#create_buf(0, a:lines)
|
||||
let res = coc#float#create_float_win(0, bufnr, opts)
|
||||
if empty(res)
|
||||
return
|
||||
endif
|
||||
if get(a:config, 'cursorline', 0)
|
||||
call s:place_sign(bufnr, 1)
|
||||
endif
|
||||
if has('nvim')
|
||||
if get(a:config, 'cursorline', 0)
|
||||
execute 'sign place 6 line=1 name=CocCurrentLine buffer='.bufnr
|
||||
endif
|
||||
redraw
|
||||
call coc#float#nvim_scrollbar(res[0])
|
||||
endif
|
||||
|
@ -474,13 +511,68 @@ function! coc#dialog#change_loading(winid, loading) abort
|
|||
call setwinvar(winid, '&winhl', getwinvar(a:winid, '&winhl'))
|
||||
endif
|
||||
call setwinvar(winid, 'kind', 'loading')
|
||||
call setbufvar(bufnr, 'target', a:winid)
|
||||
call setbufvar(bufnr, 'target_winid', a:winid)
|
||||
call setbufvar(bufnr, 'popup', winid)
|
||||
call coc#float#add_related(winid, a:winid)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Update list with new lines and highlights
|
||||
function! coc#dialog#update_list(winid, bufnr, lines, highlights) abort
|
||||
if coc#window#tabnr(a:winid) == tabpagenr()
|
||||
if getwinvar(a:winid, 'auto_height', 0)
|
||||
let row = coc#float#get_row(a:winid)
|
||||
" core height
|
||||
let height = max([1, len(copy(a:lines))])
|
||||
let height = min([getwinvar(a:winid, 'max_height', 10), height, &lines - &cmdheight - 1 - row])
|
||||
let curr = s:is_vim ? popup_getpos(a:winid)['core_height'] : nvim_win_get_height(a:winid)
|
||||
let delta = height - curr
|
||||
if delta != 0
|
||||
call coc#float#change_height(a:winid, delta)
|
||||
endif
|
||||
endif
|
||||
call coc#compat#buf_set_lines(a:bufnr, 0, -1, a:lines)
|
||||
call coc#highlight#add_highlights(a:winid, [], a:highlights)
|
||||
if s:is_vim
|
||||
let target = getwinvar(a:winid, 'target_winid', -1)
|
||||
if target != -1
|
||||
call coc#dialog#check_scroll_vim(target)
|
||||
endif
|
||||
call win_execute(a:winid, 'exe 1')
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Fix width of prompt window same as list window on scrollbar change
|
||||
function! coc#dialog#check_scroll_vim(winid) abort
|
||||
if s:is_vim && coc#float#valid(a:winid)
|
||||
let winid = coc#float#get_related(a:winid, 'list')
|
||||
if winid
|
||||
redraw
|
||||
let pos = popup_getpos(winid)
|
||||
let width = pos['width'] + (pos['scrollbar'] ? 1 : 0)
|
||||
if width != popup_getpos(a:winid)['width']
|
||||
call popup_move(a:winid, {
|
||||
\ 'minwidth': width - 2,
|
||||
\ 'maxwidth': width - 2,
|
||||
\ })
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! coc#dialog#set_cursor(winid, bufnr, line) abort
|
||||
if s:is_vim
|
||||
call coc#compat#execute(a:winid, 'exe '.a:line, 'silent!')
|
||||
call popup_setoptions(a:winid, {'cursorline' : 1})
|
||||
call popup_setoptions(a:winid, {'cursorline' : 0})
|
||||
else
|
||||
call nvim_win_set_cursor(a:winid, [a:line, 0])
|
||||
endif
|
||||
call s:place_sign(a:bufnr, a:line)
|
||||
endfunction
|
||||
|
||||
" Could be center(with optional marginTop) or cursor
|
||||
function! s:get_prompt_dimension(title, default, opts) abort
|
||||
let relative = get(a:opts, 'position', 'cursor') ==# 'cursor' ? 'cursor' : 'editor'
|
||||
|
@ -510,29 +602,12 @@ function! s:get_prompt_dimension(title, default, opts) abort
|
|||
endif
|
||||
let config = {
|
||||
\ 'col': float2nr((&columns - width) / 2),
|
||||
\ 'row': row,
|
||||
\ 'row': row - s:is_vim,
|
||||
\ }
|
||||
endif
|
||||
return extend(config, {'relative': relative, 'width': width, 'height': 1})
|
||||
endfunction
|
||||
|
||||
function! s:check_term_buffer(current, bufnr) abort
|
||||
if bufloaded(a:bufnr)
|
||||
let text = term_getline(a:bufnr, '.')
|
||||
if text !=# a:current
|
||||
let cursor = term_getcursor(a:bufnr)
|
||||
let info = {
|
||||
\ 'lnum': cursor[0],
|
||||
\ 'col': cursor[1],
|
||||
\ 'line': text ==# ' ' && cursor[1] == 1 ? '' : text,
|
||||
\ 'changedtick': 0
|
||||
\ }
|
||||
call coc#rpc#notify('CocAutocmd', ['TextChangedI', a:bufnr, info])
|
||||
endif
|
||||
call timer_start(50, { -> s:check_term_buffer(text, a:bufnr)})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:min_btns_width(buttons) abort
|
||||
if empty(a:buttons)
|
||||
return 0
|
||||
|
@ -566,7 +641,7 @@ endfunction
|
|||
|
||||
function! s:change_loading_buf(bufnr, idx) abort
|
||||
if bufloaded(a:bufnr)
|
||||
let target = getbufvar(a:bufnr, 'target', v:null)
|
||||
let target = getbufvar(a:bufnr, 'target_winid', v:null)
|
||||
if !empty(target) && !coc#float#valid(target)
|
||||
call coc#float#close(getbufvar(a:bufnr, 'popup'))
|
||||
return
|
||||
|
@ -578,3 +653,8 @@ function! s:change_loading_buf(bufnr, idx) abort
|
|||
call timer_start(100, { -> s:change_loading_buf(a:bufnr, idx)})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:place_sign(bufnr, line) abort
|
||||
call sign_unplace(s:sign_group, { 'buffer': a:bufnr })
|
||||
call sign_place(6, s:sign_group, 'CocCurrentLine', a:bufnr, {'lnum': a:line})
|
||||
endfunction
|
||||
|
|
|
@ -72,8 +72,8 @@ function! coc#float#change_height(winid, delta) abort
|
|||
\ })
|
||||
endif
|
||||
else
|
||||
let winids = coc#window#get_var(a:winid, 'related', [])
|
||||
call filter(copy(winids), 'index(["border","pad","scrollbar"],coc#window#get_var(v:val,"kind","")) >= 0')
|
||||
let winids = copy(coc#window#get_var(a:winid, 'related', []))
|
||||
call filter(winids, 'index(["border","pad","scrollbar"],coc#window#get_var(v:val,"kind","")) >= 0')
|
||||
call add(winids, a:winid)
|
||||
for winid in winids
|
||||
if coc#window#get_var(winid, 'kind', '') ==# 'border'
|
||||
|
@ -111,6 +111,9 @@ endfunction
|
|||
" - winblend: (optional) winblend option for float window, neovim only.
|
||||
" - shadow: (optional) use shadow as border style, neovim only.
|
||||
" - focusable: (optional) neovim only, default to true.
|
||||
" - scrollinside: (optional) neovim only, create scrollbar inside window.
|
||||
" - rounded: (optional) use rounded borderchars, ignored when borderchars exists.
|
||||
" - borderchars: (optional) borderchars, should be length of 8
|
||||
function! coc#float#create_float_win(winid, bufnr, config) abort
|
||||
let lines = get(a:config, 'lines', v:null)
|
||||
let bufnr = coc#float#create_buf(a:bufnr, lines, 'hide')
|
||||
|
@ -152,13 +155,14 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
|
|||
let title = get(a:config, 'title', '')
|
||||
let buttons = get(a:config, 'buttons', [])
|
||||
let hlgroup = get(a:config, 'highlight', 'CocFloating')
|
||||
let border = s:empty_border(get(a:config, 'border', [])) ? [0, 0, 0, 0] : a:config['border']
|
||||
let opts = {
|
||||
\ 'title': title,
|
||||
\ 'line': line,
|
||||
\ 'col': col,
|
||||
\ 'fixed': 1,
|
||||
\ 'padding': empty(title) ? [0, 1, 0, 1] : [0, 0, 0, 0],
|
||||
\ 'borderchars': get(a:config, 'rounded', 0) ? s:rounded_borderchars : s:borderchars,
|
||||
\ 'padding': [0, !border[1], 0, !border[3]],
|
||||
\ 'borderchars': s:get_borderchars(a:config),
|
||||
\ 'highlight': hlgroup,
|
||||
\ 'cursorline': get(a:config, 'cursorline', 0),
|
||||
\ 'minwidth': a:config['width'],
|
||||
|
@ -166,7 +170,8 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
|
|||
\ 'maxwidth': a:config['width'],
|
||||
\ 'maxheight': a:config['height'],
|
||||
\ 'close': get(a:config, 'close', 0) ? 'button' : 'none',
|
||||
\ 'border': s:empty_border(get(a:config, 'border', [])) ? [0, 0, 0, 0] : a:config['border']
|
||||
\ 'border': border,
|
||||
\ 'callback': { -> coc#float#on_close(winid)}
|
||||
\ }
|
||||
if !empty(get(a:config, 'borderhighlight', v:null))
|
||||
let borderhighlight = a:config['borderhighlight']
|
||||
|
@ -192,7 +197,9 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
|
|||
let hlgroup = get(a:config, 'highlight', 'CocFloating')
|
||||
call setwinvar(winid, '&winhl', 'Normal:'.hlgroup.',NormalNC:'.hlgroup.',FoldColumn:'.hlgroup)
|
||||
call setwinvar(winid, 'border', get(a:config, 'border', []))
|
||||
call setwinvar(winid, 'scrollinside', get(a:config, 'scrollinside', 0))
|
||||
call setwinvar(winid, '&foldcolumn', s:nvim_enable_foldcolumn(get(a:config, 'border', v:null)))
|
||||
call setwinvar(winid, '&cursorline', get(a:config, 'cursorline', 0))
|
||||
" cursorline highlight not work on old neovim
|
||||
call s:nvim_set_defaults(winid)
|
||||
call nvim_win_set_cursor(winid, [1, 0])
|
||||
|
@ -209,7 +216,7 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
|
|||
call setwinvar(winid, '&showbreak', 'NONE')
|
||||
endif
|
||||
call setwinvar(winid, 'float', 1)
|
||||
call setwinvar(winid, '&wrap', 1)
|
||||
call setwinvar(winid, '&wrap', !get(a:config, 'cursorline', 0))
|
||||
call setwinvar(winid, '&linebreak', 1)
|
||||
call setwinvar(winid, '&conceallevel', 0)
|
||||
call s:add_highlights(winid, a:config, 1)
|
||||
|
@ -239,7 +246,8 @@ function! coc#float#nvim_create_related(winid, config, opts) abort
|
|||
call coc#float#close_related(a:winid, 'buttons')
|
||||
endif
|
||||
if !s:empty_border(border)
|
||||
call coc#float#nvim_border_win(a:config, get(a:opts, 'rounded', 0), a:winid, border, get(a:opts, 'title', ''), !empty(buttons), borderhighlight, shadow, related)
|
||||
let borderchars = s:get_borderchars(a:opts)
|
||||
call coc#float#nvim_border_win(a:config, borderchars, a:winid, border, get(a:opts, 'title', ''), !empty(buttons), borderhighlight, shadow, related)
|
||||
elseif exists
|
||||
call coc#float#close_related(a:winid, 'border')
|
||||
endif
|
||||
|
@ -253,13 +261,13 @@ function! coc#float#nvim_create_related(winid, config, opts) abort
|
|||
endfunction
|
||||
|
||||
" border window for neovim, content config with border
|
||||
function! coc#float#nvim_border_win(config, rounded, winid, border, title, hasbtn, hlgroup, shadow, related) abort
|
||||
function! coc#float#nvim_border_win(config, borderchars, winid, border, title, hasbtn, hlgroup, shadow, related) abort
|
||||
let winid = coc#float#get_related(a:winid, 'border')
|
||||
let row = a:border[0] ? a:config['row'] - 1 : a:config['row']
|
||||
let col = a:border[3] ? a:config['col'] - 1 : a:config['col']
|
||||
let width = a:config['width'] + a:border[1] + a:border[3]
|
||||
let height = a:config['height'] + a:border[0] + a:border[2] + (a:hasbtn ? 2 : 0)
|
||||
let lines = coc#float#create_border_lines(a:border, a:rounded, a:title, a:config['width'], a:config['height'], a:hasbtn)
|
||||
let lines = coc#float#create_border_lines(a:border, a:borderchars, a:title, a:config['width'], a:config['height'], a:hasbtn)
|
||||
let bufnr = winid ? winbufnr(winid) : 0
|
||||
let bufnr = coc#float#create_buf(bufnr, lines)
|
||||
let opt = {
|
||||
|
@ -424,7 +432,7 @@ endfunction
|
|||
" Create or refresh scrollbar for winid
|
||||
" Need called on create, config, buffer change, scrolled
|
||||
function! coc#float#nvim_scrollbar(winid) abort
|
||||
if !has('nvim-0.4.0') || coc#window#get_var(a:winid, 'target_winid', 0)
|
||||
if !has('nvim-0.4.0')
|
||||
return
|
||||
endif
|
||||
let winids = nvim_tabpage_list_wins(nvim_get_current_tabpage())
|
||||
|
@ -446,6 +454,7 @@ function! coc#float#nvim_scrollbar(winid) abort
|
|||
let ch = coc#float#content_height(bufnr, cw, getwinvar(a:winid, '&wrap'))
|
||||
let closewin = coc#float#get_related(a:winid, 'close')
|
||||
let border = getwinvar(a:winid, 'border', [])
|
||||
let scrollinside = getwinvar(a:winid, 'scrollinside', 0) && get(border, 1, 0)
|
||||
let winblend = getwinvar(a:winid, '&winblend', 0)
|
||||
let move_down = closewin && !get(border, 0, 0)
|
||||
let id = coc#float#get_related(a:winid, 'scrollbar')
|
||||
|
@ -464,7 +473,7 @@ function! coc#float#nvim_scrollbar(winid) abort
|
|||
let sbuf = coc#float#create_buf(sbuf, repeat([' '], height))
|
||||
let opts = {
|
||||
\ 'row': move_down ? row + 1 : row,
|
||||
\ 'col': column + width,
|
||||
\ 'col': column + width - scrollinside,
|
||||
\ 'relative': relative,
|
||||
\ 'width': 1,
|
||||
\ 'height': height,
|
||||
|
@ -488,7 +497,9 @@ function! coc#float#nvim_scrollbar(winid) abort
|
|||
call setwinvar(id, 'target_winid', a:winid)
|
||||
call coc#float#add_related(id, a:winid)
|
||||
endif
|
||||
call coc#float#nvim_scroll_adjust(a:winid)
|
||||
if !scrollinside
|
||||
call coc#float#nvim_scroll_adjust(a:winid)
|
||||
endif
|
||||
let thumb_height = max([1, float2nr(floor(height * (height + 0.0)/ch))])
|
||||
let wininfo = getwininfo(a:winid)[0]
|
||||
let start = 0
|
||||
|
@ -514,8 +525,8 @@ function! coc#float#nvim_scrollbar(winid) abort
|
|||
endfor
|
||||
endfunction
|
||||
|
||||
function! coc#float#create_border_lines(border, rounded, title, width, height, hasbtn) abort
|
||||
let borderchars = a:rounded ? s:rounded_borderchars : s:borderchars
|
||||
function! coc#float#create_border_lines(border, borderchars, title, width, height, hasbtn) abort
|
||||
let borderchars = a:borderchars
|
||||
let list = []
|
||||
if a:border[0]
|
||||
let top = (a:border[3] ? borderchars[4]: '')
|
||||
|
@ -684,6 +695,16 @@ function! coc#float#nvim_refresh_scrollbar(winid) abort
|
|||
endif
|
||||
endfunction
|
||||
|
||||
function! coc#float#on_close(winid) abort
|
||||
let winids = coc#float#get_float_win_list()
|
||||
for winid in winids
|
||||
let target = getwinvar(winid, 'target_winid', -1)
|
||||
if target == a:winid
|
||||
call coc#float#close(winid)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Close related windows, or specific kind
|
||||
function! coc#float#close_related(winid, ...) abort
|
||||
if !coc#float#valid(a:winid)
|
||||
|
@ -696,11 +717,14 @@ function! coc#float#close_related(winid, ...) abort
|
|||
let kind = get(a:, 1, '')
|
||||
let winids = coc#window#get_var(a:winid, 'related', [])
|
||||
for id in winids
|
||||
if s:is_vim
|
||||
" vim doesn't throw
|
||||
noa call popup_close(id)
|
||||
else
|
||||
if empty(kind) || coc#window#get_var(id, 'kind', '') ==# kind
|
||||
let curr = coc#window#get_var(id, 'kind', '')
|
||||
if empty(kind) || curr ==# kind
|
||||
if curr == 'list'
|
||||
call coc#float#close(id)
|
||||
elseif s:is_vim
|
||||
" vim doesn't throw
|
||||
noa call popup_close(id)
|
||||
else
|
||||
silent! noa call nvim_win_close(id, 1)
|
||||
endif
|
||||
endif
|
||||
|
@ -863,7 +887,7 @@ function! coc#float#vim_filter(winid, key, keys) abort
|
|||
return 0
|
||||
endfunction
|
||||
|
||||
function! coc#float#get_related(winid, kind) abort
|
||||
function! coc#float#get_related(winid, kind, ...) abort
|
||||
if coc#float#valid(a:winid)
|
||||
for winid in coc#window#get_var(a:winid, 'related', [])
|
||||
if coc#window#get_var(winid, 'kind', '') ==# a:kind
|
||||
|
@ -871,7 +895,19 @@ function! coc#float#get_related(winid, kind) abort
|
|||
endif
|
||||
endfor
|
||||
endif
|
||||
return 0
|
||||
return get(a:, 1, 0)
|
||||
endfunction
|
||||
|
||||
function! coc#float#get_row(winid) abort
|
||||
let winid = s:is_vim ? a:winid : coc#float#get_related(a:winid, 'border', a:winid)
|
||||
if coc#float#valid(winid)
|
||||
if s:is_vim
|
||||
let pos = popup_getpos(winid)
|
||||
return pos['line'] - 1
|
||||
endif
|
||||
let pos = nvim_win_get_position(winid)
|
||||
return pos[0]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Create temporarily buffer with optional lines and &bufhidden
|
||||
|
@ -1265,13 +1301,15 @@ function! s:win_setview(winid, topline, lnum) abort
|
|||
endfunction
|
||||
|
||||
function! s:nvim_set_defaults(winid) abort
|
||||
call setwinvar(a:winid, '&cursorline', 0)
|
||||
call setwinvar(a:winid, '&signcolumn', 'auto')
|
||||
call setwinvar(a:winid, '&list', 0)
|
||||
call setwinvar(a:winid, '&number', 0)
|
||||
call setwinvar(a:winid, '&relativenumber', 0)
|
||||
call setwinvar(a:winid, '&cursorcolumn', 0)
|
||||
call setwinvar(a:winid, '&colorcolumn', 0)
|
||||
if exists('*win_execute')
|
||||
call win_execute(a:winid, 'setl fillchars+=eob:\ ')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:nvim_add_related(winid, target, kind, winhl, related) abort
|
||||
|
@ -1321,11 +1359,16 @@ function! s:add_highlights(winid, config, create) abort
|
|||
endfunction
|
||||
|
||||
function! s:empty_border(border) abort
|
||||
if empty(a:border)
|
||||
return 1
|
||||
endif
|
||||
if a:border[0] == 0 && a:border[1] == 0 && a:border[2] == 0 && a:border[3] == 0
|
||||
if empty(a:border) || empty(filter(copy(a:border), 'v:val != 0'))
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:get_borderchars(config) abort
|
||||
let borderchars = get(a:config, 'borderchars', [])
|
||||
if !empty(borderchars)
|
||||
return borderchars
|
||||
endif
|
||||
return get(a:config, 'rounded', 0) ? s:rounded_borderchars : s:borderchars
|
||||
endfunction
|
||||
|
|
|
@ -5,7 +5,8 @@ const readline = require("readline")
|
|||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
escapeCodeTimeout: 0
|
||||
escapeCodeTimeout: 0,
|
||||
prompt: ''
|
||||
})
|
||||
rl.setPrompt('')
|
||||
let value = process.argv[2]
|
||||
|
@ -13,37 +14,70 @@ if (value) {
|
|||
rl.write(value)
|
||||
}
|
||||
rl.on('line', input => {
|
||||
let text = input.replace(/"/g, '\\"')
|
||||
console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['confirm', text]])))
|
||||
send(['confirm', input])
|
||||
process.exit()
|
||||
})
|
||||
|
||||
let original_ttyWrite = rl._ttyWrite
|
||||
rl._ttyWrite = function (code, key) {
|
||||
if (key.name === 'enter') {
|
||||
send(['send', '<C-j>'])
|
||||
return ''
|
||||
}
|
||||
original_ttyWrite.apply(rl, arguments)
|
||||
send(['change', rl.line])
|
||||
}
|
||||
|
||||
function createSequences(str) {
|
||||
return '\033]51;' + str + '\x07'
|
||||
}
|
||||
|
||||
process.stdin.on('keypress', (_, key) => {
|
||||
function send(args) {
|
||||
process.stdout.write(createSequences(JSON.stringify(['call', 'CocPopupCallback', args])))
|
||||
}
|
||||
|
||||
process.stdin.on('keypress', (e, key) => {
|
||||
if (key) {
|
||||
let k = getKey(key)
|
||||
if (k == '<bs>') {
|
||||
return
|
||||
}
|
||||
if (k == '<cr>') {
|
||||
process.exit()
|
||||
return
|
||||
}
|
||||
if (k == '<esc>') {
|
||||
console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['exit', '']])))
|
||||
send(['exit', ''])
|
||||
process.exit()
|
||||
return
|
||||
}
|
||||
if (k) {
|
||||
console.log(createSequences(JSON.stringify(['call', 'CocPopupCallback', ['send', k]])))
|
||||
send(['send', k])
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function getKey(key) {
|
||||
if (key.ctrl === true) {
|
||||
if (key.name == 'n') {
|
||||
return '<C-n>'
|
||||
}
|
||||
if (key.name == 'p') {
|
||||
return '<C-p>'
|
||||
}
|
||||
if (key.name == 'j') {
|
||||
return '<C-j>'
|
||||
}
|
||||
if (key.name == 'k') {
|
||||
return '<C-k>'
|
||||
}
|
||||
if (key.name == 'f') {
|
||||
return '<C-f>'
|
||||
}
|
||||
if (key.name == 'b') {
|
||||
return '<C-b>'
|
||||
}
|
||||
if (key.sequence == '\x00') {
|
||||
return '<C-@>'
|
||||
}
|
||||
}
|
||||
if (key.sequence == '\u001b') {
|
||||
return '<esc>'
|
||||
}
|
||||
|
@ -53,16 +87,6 @@ function getKey(key) {
|
|||
if (key.sequence == '\t') {
|
||||
return key.shift ? '<s-tab>' : '<tab>'
|
||||
}
|
||||
// handle them can cause bug with terminal
|
||||
// if (key.name == 'backspace') {
|
||||
// return '<bs>'
|
||||
// }
|
||||
// if (key.name == 'left') {
|
||||
// return '<left>'
|
||||
// }
|
||||
// if (key.name == 'right') {
|
||||
// return '<right>'
|
||||
// }
|
||||
if (key.name == 'up') {
|
||||
return '<up>'
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1983,7 +1983,7 @@ g:coc_process_pid *g:coc_process_pid*
|
|||
<
|
||||
in your vimrc.
|
||||
|
||||
g:coc_service_initialized *g:coc_service_initialized*
|
||||
g:coc_service_initialized *g:coc_service_initialized*
|
||||
|
||||
Is `1` when coc.nvim initialized, used with autocmd |CocNvimInit|.
|
||||
|
||||
|
@ -3196,13 +3196,13 @@ characters.
|
|||
|
||||
Others~
|
||||
|
||||
*CocSearch* highlight group for matched characters in list.
|
||||
*CocDisabled* highlight for disabled items, eg: menu item.
|
||||
*CocCodeLens* for virtual text of codeLens.
|
||||
*CocCursorRange* for highlight of activated cursors ranges.
|
||||
*CocLinkedEditing* for highlight of activated linked editing ranges.
|
||||
*CocHoverRange* for range of current hovered symbol.
|
||||
*CocMenuSel* for current menu item in menu dialog, works on neovim only since
|
||||
vim doesn't support change highlight group of cursorline inside popup.
|
||||
*CocMenuSel* for current menu item in menu dialog.
|
||||
*CocSelectedRange* for highlight ranges of outgoing calls.
|
||||
*CocSnippetVisual* for highlight snippet placeholders.
|
||||
*CocInlayHint* for highlight inlay hint virtual text block, default linked to
|
||||
|
@ -3814,15 +3814,41 @@ A input dialog request user input with optional default value, normally
|
|||
created by `window.requestInput`, when `"coc.preferences.promptInput"` is
|
||||
false, vim's commandline input prompt is used instead.
|
||||
|
||||
On neovim, it uses float window, on vim8, it opens terminal in popup.
|
||||
|
||||
Supported key-mappings:
|
||||
|
||||
<C-a> - move cursor to first col.
|
||||
<C-e> - move cursor to last col.
|
||||
<esc> - cancel input, an empty string is received by callback.
|
||||
<cr> - confirm selection of current item, use
|
||||
|dialog.confirmKey| to override.
|
||||
<C-a> - move cursor to first col.
|
||||
<C-e> - move cursor to last col.
|
||||
<esc> - cancel input, null is received by callback.
|
||||
<cr> - accept current input selection of current item.
|
||||
|
||||
And other insert mode key-mappings that your neovim provided.
|
||||
QuickPick related (available when created by |coc-dialog-quickpick|).
|
||||
|
||||
<C-f> - scroll forward quickpick list.
|
||||
<C-b> - scroll backward quickpick list.
|
||||
<C-j> <C-n> <down> - move to next item in quickpick list.
|
||||
<C-k> <C-p> <up> - move to previous item in quickpick list.
|
||||
<C-space> - toggle selection of current item in quickpick list when
|
||||
canSelectMany is supported.
|
||||
|
||||
Note on neovim, other insert mode key-mappings could work.
|
||||
|
||||
Note not possible to configure key-mappings on vim8, to customize key-mappings
|
||||
on neovim, use |CocOpenFloatPrompt| with current buffer.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
*coc-dialog-quickpick*
|
||||
|
||||
A quickpick is a input dialog in the middle with a float window/popup contains
|
||||
filtred list items.
|
||||
|
||||
A simple fuzzy filter is used by default.
|
||||
|
||||
See |coc-config-dialog| for available configurations.
|
||||
|
||||
See |coc-dialog-input| for available key-mappings.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
# 2022-05-17
|
||||
|
||||
- Add `QuickPick` module.
|
||||
- Add API `window.showQuickPick()` and `window.createQuickPick()`.
|
||||
|
||||
# 2022-05-16
|
||||
|
||||
- Add properties `title`, `loading` & `borderhighlight` to `InputBox`
|
||||
|
|
|
@ -64,6 +64,24 @@ function! CocPopupCallback(bufnr, arglist) abort
|
|||
elseif a:arglist[0] == 'exit'
|
||||
execute 'silent! bd! '.a:bufnr
|
||||
"call coc#rpc#notify('PromptUpdate', [a:arglist[1]])
|
||||
elseif a:arglist[0] == 'change'
|
||||
let text = a:arglist[1]
|
||||
let current = getbufvar(a:bufnr, 'current', '')
|
||||
if text !=# current
|
||||
call setbufvar(a:bufnr, 'current', text)
|
||||
let cursor = term_getcursor(a:bufnr)
|
||||
let info = {
|
||||
\ 'lnum': cursor[0],
|
||||
\ 'col': cursor[1],
|
||||
\ 'line': text,
|
||||
\ 'changedtick': 0
|
||||
\ }
|
||||
call coc#rpc#notify('CocAutocmd', ['TextChangedI', a:bufnr, info])
|
||||
endif
|
||||
elseif a:arglist[0] == 'send'
|
||||
let key = a:arglist[1]
|
||||
let escaped = strcharpart(key, 1, strchars(key) - 2)
|
||||
call coc#rpc#notify('PromptKeyPress', [a:bufnr, escaped])
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
@ -321,7 +339,7 @@ function! s:Enable(initialize)
|
|||
autocmd WinEnter * call coc#float#nvim_win_enter(win_getid())
|
||||
endif
|
||||
if exists('##WinClosed')
|
||||
autocmd WinClosed * call coc#float#close_related(+expand('<amatch>'))
|
||||
autocmd WinClosed * call coc#float#on_close(+expand('<amatch>'))
|
||||
autocmd WinClosed * call coc#notify#on_close(+expand('<amatch>'))
|
||||
elseif exists('##TabEnter')
|
||||
autocmd TabEnter * call coc#notify#reflow()
|
||||
|
|
Loading…
Reference in a new issue