Skip to content

Commit 144ce8d

Browse files
authored
Merge pull request #2678 from bhcleek/util/highlight/multi-line
util: text property end_col calculation
2 parents 025af24 + ed5a4de commit 144ce8d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

autoload/go/util.vim

+10-8
Original file line numberDiff line numberDiff line change
@@ -620,23 +620,25 @@ function! go#util#HighlightPositions(group, pos) abort
620620

621621
" l:max is the 1-based index within the buffer of the first character after l:pos.
622622
let l:max = line2byte(l:pos[0]) + l:pos[1] + l:pos[2] - 1
623-
624623
if has('patch-8.2.115')
625624
" Use byte2line as long as 8.2.115 (which resolved
626625
" https://github.com/vim/vim/issues/5334) is available.
627-
let l:end_lnum = byte2line(l:max)
626+
let l:end_lnum = byte2line(l:max)
628627

629-
if l:pos[0] != l:end_lnum
630-
let l:end_col = l:max - line2byte(l:end_lnum)
631-
let l:prop = {'type': a:group, 'end_lnum': l:end_lnum, 'end_col': l:end_col}
632-
endif
628+
if l:pos[0] != l:end_lnum
629+
let l:end_col = l:max - line2byte(l:end_lnum)
630+
let l:prop = {'type': a:group, 'end_lnum': l:end_lnum, 'end_col': l:end_col}
631+
endif
633632
elseif l:pos[1] + l:pos[2] - 1 > len(l:line)
634633
let l:end_lnum = l:pos[0]
635-
let l:end_col = l:pos[1] + l:pos[2] - 1
636634
while line2byte(l:end_lnum+1) < l:max
637635
let l:end_lnum += 1
638-
let l:end_col -= line2byte(l:end_lnum)
639636
endwhile
637+
638+
" l:end_col is the full length - the byte position of l:end_lnum +
639+
" the number of newlines (number of newlines is l:end_lnum -
640+
" l:pos[0].
641+
let l:end_col = l:max - line2byte(l:end_lnum) + l:end_lnum - l:pos[0]
640642
let l:prop = {'type': a:group, 'end_lnum': l:end_lnum, 'end_col': l:end_col}
641643
endif
642644
call prop_add(l:pos[0], l:pos[1], l:prop)

0 commit comments

Comments
 (0)