From 8aaadf2c2c3759576a4604c727b05ce14080d3db Mon Sep 17 00:00:00 2001 From: Kyosuke Fujimoto Date: Sat, 21 Sep 2024 09:56:34 +0900 Subject: [PATCH 1/2] Fix to use lines() instead of split('\n') --- src/widget/text_preview.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/text_preview.rs b/src/widget/text_preview.rs index 0b9e601..6b5e1a9 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.split('\n').map(|s| Line::raw(s.to_string())).collect() + s.lines().map(|s| Line::raw(s.to_string())).collect() } }; From 72618e0ee8d66fbaa5528f34452459fe1f87d0c6 Mon Sep 17 00:00:00 2001 From: Kyosuke Fujimoto Date: Sat, 21 Sep 2024 09:57:46 +0900 Subject: [PATCH 2/2] Filter control characters --- src/widget/text_preview.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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,