Fix preview panel UTF-8 panics and preserve whitespace in redactions
Snap byte offsets to character boundaries in the preview layout to prevent slicing inside multi-byte characters. Preserve all whitespace (not just newlines) in redacted regions. Force dark theme explicitly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -55,6 +55,7 @@ fn configure_fonts(ctx: &egui::Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_nord_theme(ctx: &egui::Context) {
|
fn apply_nord_theme(ctx: &egui::Context) {
|
||||||
|
ctx.set_theme(egui::Theme::Dark);
|
||||||
let mut style = (*ctx.style()).clone();
|
let mut style = (*ctx.style()).clone();
|
||||||
let v = &mut style.visuals;
|
let v = &mut style.visuals;
|
||||||
|
|
||||||
@@ -403,8 +404,8 @@ impl eframe::App for RedactorApp {
|
|||||||
&self_redactions,
|
&self_redactions,
|
||||||
r.end,
|
r.end,
|
||||||
);
|
);
|
||||||
let os = out_start.min(text.len());
|
let os = snap_to_char_boundary(text, out_start.min(text.len()));
|
||||||
let oe = out_end.min(text.len());
|
let oe = snap_to_char_boundary(text, out_end.min(text.len()));
|
||||||
|
|
||||||
if pos < os {
|
if pos < os {
|
||||||
job.append(&text[pos..os], 0.0, normal.clone());
|
job.append(&text[pos..os], 0.0, normal.clone());
|
||||||
@@ -437,6 +438,13 @@ impl eframe::App for RedactorApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn snap_to_char_boundary(s: &str, mut i: usize) -> usize {
|
||||||
|
while i > 0 && !s.is_char_boundary(i) {
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
i
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
fn byte_to_preview_byte_static(
|
fn byte_to_preview_byte_static(
|
||||||
source: &str,
|
source: &str,
|
||||||
@@ -471,7 +479,7 @@ fn byte_to_preview_byte_static(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ch in source[r_start..r_end].chars() {
|
for ch in source[r_start..r_end].chars() {
|
||||||
if ch == '\n' || ch == '\r' {
|
if ch.is_whitespace() {
|
||||||
preview_pos += ch.len_utf8();
|
preview_pos += ch.len_utf8();
|
||||||
} else {
|
} else {
|
||||||
preview_pos += '\u{2588}'.len_utf8();
|
preview_pos += '\u{2588}'.len_utf8();
|
||||||
|
|||||||
Reference in New Issue
Block a user