1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 12:50:04 -04:00

Use strongly typed CharIndex and ByteIndex + bug fixes (#8245)

Less risk of confusing the two.

Found and fix a couple real bugs in the process!

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Emil Ernerfeldt
2026-06-21 02:24:00 +02:00
committed by GitHub
parent eac51da9ca
commit 13d6b5afcf
15 changed files with 396 additions and 138 deletions

View File

@@ -604,7 +604,8 @@ impl Highlighter {
}
#[cfg(feature = "syntect")]
fn as_byte_range(whole: &str, range: &str) -> std::ops::Range<usize> {
fn as_byte_range(whole: &str, range: &str) -> std::ops::Range<egui::text::ByteIndex> {
use egui::text::ByteIndex;
let whole_start = whole.as_ptr() as usize;
let range_start = range.as_ptr() as usize;
assert!(
@@ -617,7 +618,7 @@ fn as_byte_range(whole: &str, range: &str) -> std::ops::Range<usize> {
range_start + range.len()
);
let offset = range_start - whole_start;
offset..(offset + range.len())
ByteIndex(offset)..ByteIndex(offset + range.len())
}
// ----------------------------------------------------------------------------