diff --git a/autoload/go/util.vim b/autoload/go/util.vim index 14abf1568b..9e4a9bfd5b 100644 --- a/autoload/go/util.vim +++ b/autoload/go/util.vim @@ -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)