Skip to content

Commit 3684aca

Browse files
committed
fix character range off-by-one error
- triggered by calling measureText with multiple `\n`s in a row (leading to zero-width lines of typesetting that still consumed one character from the string (see samizdatco#96)
1 parent 53c1941 commit 3684aca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn string_idx_range(text: &str, start_idx: usize, end_idx: usize) -> Range<u
150150

151151
Range{
152152
start: indices.nth(start_idx).map_or(str_len, &obtain_index),
153-
end: indices.nth(end_idx - start_idx - 1).map_or(str_len, &obtain_index),
153+
end: indices.nth((end_idx - start_idx).max(1) - 1).map_or(str_len, &obtain_index),
154154
}
155155
}
156156

0 commit comments

Comments
 (0)