Skip to content

util: text property end_col calculation #2678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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