diff --git a/src/widget/text_preview.rs b/src/widget/text_preview.rs index 6b5e1a9..83aa2ba 100644 --- a/src/widget/text_preview.rs +++ b/src/widget/text_preview.rs @@ -46,7 +46,7 @@ impl TextPreviewState { if let Some(msg) = msg { warn_msg = Some(msg); } - s.lines().map(|s| Line::raw(s.to_string())).collect() + s.lines().map(drop_control_chars).map(Line::raw).collect() } }; @@ -68,6 +68,10 @@ fn to_preview_string(bytes: &[u8]) -> String { } } +fn drop_control_chars(s: &str) -> String { + s.chars().filter(|c| !c.is_control()).collect() +} + fn build_highlighted_lines( s: &str, file_name: &str,