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
58
58
" Inputs are 1-based (row, col) coordinates into lines.
59
59
" Returns the corresponding zero-based offset into lines->join("\n")
60
60
function ! 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
62
62
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
65
65
endfor
66
66
endif
67
67
return l: offset
@@ -74,14 +74,14 @@ function! s:OffsetToPosition(offset, lines) abort
74
74
let l: lines_consumed = 0
75
75
let l: chars_left = a: offset
76
76
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
78
78
if l: chars_left < l: line_len
79
79
break
80
80
endif
81
81
let l: chars_left -= l: line_len
82
82
let l: lines_consumed += 1
83
83
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
85
85
endfunction
86
86
87
87
You can’t perform that action at this time.
0 commit comments