Skip to content

Commit

Permalink
commit a6e54ae
Browse files Browse the repository at this point in the history
a6e54ae fix(client): `shell=true` on windows (#5225)
dce5ae5 feat(plugin): improve argument typing (#5221)
77094cb docs: correct coc-example-config url (#5220)
1e7abfa feat(scope): ensureDocument can accept bufnr (#5219)
28ad86d feat: add fixed position support for floating windows (#5217)
6a338ca fix(codeLens): Misalign when using tabs as indent (#5214)
306d7b9 fix(plugin): gramma on Action not existing (#5213)
5ca97f5 chore: correct typos (#5212)
2816a11 chore(history.md): mentioned recently improvements (#5211)
d70a46d refactor(highlights): remove checkMarkers (#5210)
829a106 perf(highlight): increase number of highlights (#5208)
2fc3f0d fix(semanticTokens): correct end range (#5206)
00da052 feat(semanticTokens): decrease highlighting range (#5205)
  • Loading branch information
fannheyward committed Dec 24, 2024
1 parent ebe7a08 commit 4cc1694
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 108 deletions.
46 changes: 46 additions & 0 deletions autoload/coc/float.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,52 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
" happens when using getchar() #3921
return []
endtry

" Calculate position when relative is editor
if get(a:config, 'relative', '') ==# 'editor'
let top = get(a:config, 'top', v:null)
let bottom = get(a:config, 'bottom', v:null)
let left = get(a:config, 'left', v:null)
let right = get(a:config, 'right', v:null)

if top isnot v:null || bottom isnot v:null || left isnot v:null || right isnot v:null
let height = &lines
let width = &columns

" Calculate row
let calc_row = a:config.row
if bottom isnot v:null
let calc_row = height - bottom - a:config.height - 2
elseif top isnot v:null
let calc_row = top
endif

" Calculate col
let calc_col = a:config.col
if right isnot v:null
let calc_col = width - right - a:config.width - 3
elseif left isnot v:null
let calc_col = left
endif

" Check if window would overlap cursor position
let pos = screenpos(0, line('.'), col('.'))
let currow = pos.row - 1
let curcol = pos.col - 1
let win_top = calc_row
let win_bottom = win_top + a:config.height + 2
let win_left = calc_col
let win_right = win_left + a:config.width + 3

" If window would overlap cursor, switch to cursor relative
if currow >= win_top && currow <= win_bottom && curcol >= win_left && curcol <= win_right
let a:config.relative = 'cursor'
else
let a:config.row = calc_row
let a:config.col = calc_col
endif
endif
endif
let lnum = max([1, get(a:config, 'index', 0) + 1])
let zindex = get(a:config, 'zindex', 50)
" use exists
Expand Down
2 changes: 1 addition & 1 deletion autoload/coc/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let s:namespace_map = {}
let s:ns_id = 1
let s:diagnostic_hlgroups = ['CocErrorHighlight', 'CocWarningHighlight', 'CocInfoHighlight', 'CocHintHighlight', 'CocDeprecatedHighlight', 'CocUnusedHighlight']
" Maximum count to highlight each time.
let g:coc_highlight_maximum_count = get(g:, 'coc_highlight_maximum_count', 200)
let g:coc_highlight_maximum_count = get(g:, 'coc_highlight_maximum_count', 500)
let s:term = &termguicolors == 0 && !has('gui_running')

" Update buffer region by region.
Expand Down
18 changes: 17 additions & 1 deletion autoload/coc/vtext.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function! coc#vtext#add(bufnr, src_id, line, blocks, opts) abort
let type = coc#api#create_type(a:src_id, hl, a:opts)
let opts = extend({ 'text': text, 'type': type, 'bufnr': a:bufnr }, base)
if first && !empty(indent)
let opts['text'] = indent . text
let opts['text_padding_left'] = s:calc_padding_size(indent)
endif
call prop_add(a:line + 1, column, opts)
let first = 0
Expand Down Expand Up @@ -77,3 +77,19 @@ function! s:get_option_vim(align, column, wrap) abort
endif
return opts
endfunction

function! s:calc_padding_size(indent) abort
let tabSize = &shiftwidth
if tabSize == 0
let tabSize = &tabstop
endif
let padding = 0
for c in a:indent
if c == "\t"
let padding += tabSize - (padding % tabSize)
else
let padding += 1
endif
endfor
return padding
endfunction
Loading

0 comments on commit 4cc1694

Please sign in to comment.