Skip to content

Commit

Permalink
Merge pull request #2678 from bhcleek/util/highlight/multi-line
Browse files Browse the repository at this point in the history
util: text property end_col calculation
  • Loading branch information
bhcleek authored Jan 22, 2020
2 parents 025af24 + ed5a4de commit 144ce8d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -620,23 +620,25 @@ function! go#util#HighlightPositions(group, pos) abort

" l:max is the 1-based index within the buffer of the first character after l:pos.
let l:max = line2byte(l:pos[0]) + l:pos[1] + l:pos[2] - 1

if has('patch-8.2.115')
" Use byte2line as long as 8.2.115 (which resolved
" https://github.com/vim/vim/issues/5334) is available.
let l:end_lnum = byte2line(l:max)
let l:end_lnum = byte2line(l:max)

if l:pos[0] != l:end_lnum
let l:end_col = l:max - line2byte(l:end_lnum)
let l:prop = {'type': a:group, 'end_lnum': l:end_lnum, 'end_col': l:end_col}
endif
if l:pos[0] != l:end_lnum
let l:end_col = l:max - line2byte(l:end_lnum)
let l:prop = {'type': a:group, 'end_lnum': l:end_lnum, 'end_col': l:end_col}
endif
elseif l:pos[1] + l:pos[2] - 1 > len(l:line)
let l:end_lnum = l:pos[0]
let l:end_col = l:pos[1] + l:pos[2] - 1
while line2byte(l:end_lnum+1) < l:max
let l:end_lnum += 1
let l:end_col -= line2byte(l:end_lnum)
endwhile

" l:end_col is the full length - the byte position of l:end_lnum +
" the number of newlines (number of newlines is l:end_lnum -
" l:pos[0].
let l:end_col = l:max - line2byte(l:end_lnum) + l:end_lnum - l:pos[0]
let l:prop = {'type': a:group, 'end_lnum': l:end_lnum, 'end_col': l:end_col}
endif
call prop_add(l:pos[0], l:pos[1], l:prop)
Expand Down

0 comments on commit 144ce8d

Please sign in to comment.