From f1cf46f022e40cbe916be1ab496937b4eefb226d Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:01:51 +0000 Subject: [PATCH] feat: better implementation of title_case --- helix-core/src/case_conversion.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/helix-core/src/case_conversion.rs b/helix-core/src/case_conversion.rs index dd13f32dd..67bf17180 100644 --- a/helix-core/src/case_conversion.rs +++ b/helix-core/src/case_conversion.rs @@ -125,8 +125,8 @@ pub fn to_kebab_case_with(text: impl Iterator, buf: &mut Tendril) { } pub fn to_title_case_with(text: impl Iterator, buf: &mut Tendril) { - let mut at_word_start = false; - for c in text { + let mut at_word_start = true; + for (i, c) in text.enumerate() { // we don't count _ as a word char here so case conversions work well if !c.is_alphanumeric() { at_word_start = true; @@ -134,7 +134,9 @@ pub fn to_title_case_with(text: impl Iterator, buf: &mut Tendril) { } if at_word_start { at_word_start = false; - buf.push(' '); + if i != 0 { + buf.push(' '); + } buf.extend(c.to_uppercase()); } else { buf.push(c)