From ab251ec5736620efbed67d87f90410719a160eb1 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 10 Feb 2021 16:58:09 +0100 Subject: [PATCH] textwrap: do not insert spaces before punctuation Part-of: --- text/wrap/src/gsttextwrap/imp.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 0d62fd37..9c381cfd 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -91,6 +91,10 @@ pub struct TextWrap { state: Mutex, } +fn is_punctuation(word: &str) -> bool { + word == "." || word == "," || word == "?" || word == "!" || word == ";" || word == ":" +} + impl TextWrap { fn update_wrapper(&self, element: &super::TextWrap) { let settings = self.settings.lock().unwrap(); @@ -205,7 +209,7 @@ impl TextWrap { let mut current_text = state.current_text.to_string(); for word in words { - if !current_text.is_empty() { + if !current_text.is_empty() && !is_punctuation(word) { current_text.push(' '); } current_text.push_str(word);