Skip to content

Commit 9a3167e

Browse files
committed
fix: correct calculation for fields in WideChar for line-specific positions
1 parent 6557151 commit 9a3167e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/line-index/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ fn analyze_source_file_generic(
363363
let c = src[i..].chars().next().unwrap();
364364
char_len = c.len_utf8();
365365

366-
let pos = TextSize::from(i as u32) + output_offset;
366+
// The last element of `lines` represents the offset of the start of
367+
// current line. To get the offset inside the line, we subtract it.
368+
let pos = TextSize::from(i as u32) + output_offset
369+
- lines.last().unwrap_or(&TextSize::default());
367370

368371
if char_len > 1 {
369372
assert!((2..=4).contains(&char_len));

0 commit comments

Comments
 (0)