File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -58,10 +58,10 @@ endfunction
5858" Inputs are 1-based (row, col) coordinates into lines.
5959" Returns the corresponding zero-based offset into lines->join("\n")
6060function ! s: PositionToOffset (row, col , lines ) abort
61- let l: offset = a: col - 1
61+ let l: offset = a: col - 1 " 1-based to 0-based
6262 if a: row > 1
63- for l: line in a: lines [0 : a: row - 2 ]
64- let l: offset += len (l: line ) + 1
63+ for l: line in a: lines [0 : a: row - 2 ] " 1-based to 0-based, exclude current
64+ let l: offset += len (l: line ) + 1 " +1 for newline
6565 endfor
6666 endif
6767 return l: offset
@@ -74,14 +74,14 @@ function! s:OffsetToPosition(offset, lines) abort
7474 let l: lines_consumed = 0
7575 let l: chars_left = a: offset
7676 for l: line in a: lines
77- let l: line_len = len (l: line ) + 1
77+ let l: line_len = len (l: line ) + 1 " +1 for newline
7878 if l: chars_left < l: line_len
7979 break
8080 endif
8181 let l: chars_left -= l: line_len
8282 let l: lines_consumed += 1
8383 endfor
84- return [l: lines_consumed + 1 , l: chars_left + 1 ]
84+ return [l: lines_consumed + 1 , l: chars_left + 1 ] " 0-based to 1-based
8585endfunction
8686
8787
You can’t perform that action at this time.
0 commit comments