Panics · P22 Collaboration: marks outside their text stay out under the owner's index; accept answers None; zero reactions and stale masked offsets hold

This commit is contained in:
ZacharyZhang-NY committed 2026-10-07 00:17:15 -04:00
1 parent 19b0b2997a
commit 9eab2019a8
9 files changed
+215 -35

No files matched your search

+15 -2
View File
@@ -69,9 +69,12 @@ pub(crate) fn from_utf16(text: &str, offset: usize) -> usize {
text.len()
}
/// Display offset of a content offset when each grapheme shows as `bullet`.
/// Display offset of a content offset when each grapheme shows as `bullet`; an offset the text lost clamps into it.
pub(crate) fn masked_offset(text: &str, offset: usize, bullet: char) -> usize {
text[..offset].graphemes(true).count() * bullet.len_utf8()
text[..text.floor_char_boundary(offset)]
.graphemes(true)
.count()
* bullet.len_utf8()
}
/// Content offset of a display offset in masked text.
@@ -182,6 +185,16 @@ mod tests {
assert_eq!(masked_offset(text, 6, '•'), 9);
assert_eq!(unmasked_offset(text, 9, '•'), 6);
assert_eq!(unmasked_offset(text, 12, '•'), text.len());
assert_eq!(
masked_offset("a", 2, '•'),
3,
"an offset past the text clamps"
);
assert_eq!(
masked_offset(text, 4, '•'),
6,
"inside a character, before it"
);
}
#[test]