From d4e4049ab76fa8a6e6f3c7dd68b43bc19d969394 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:10:05 +0000 Subject: [PATCH] fix: add extra separator character if at camelCase boundary --- helix-core/src/case_conversion.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/helix-core/src/case_conversion.rs b/helix-core/src/case_conversion.rs index 6e37cded6..3a122ac4e 100644 --- a/helix-core/src/case_conversion.rs +++ b/helix-core/src/case_conversion.rs @@ -24,6 +24,14 @@ pub fn complex_case_conversion( for c in text.skip_while(|ch| ch.is_whitespace()) { if c.is_alphanumeric() { + if let Some(separator) = separator { + if prev.is_some_and(|p| p != separator) + && prev.is_some_and(|p| p.is_lowercase()) + && c.is_uppercase() + { + buf.push(separator); + } + } if prev.is_some_and(|p| p.is_lowercase()) && c.is_uppercase() { capitalize_next = true; } @@ -266,18 +274,18 @@ mod tests { #[test] fn test_title_case_conversion() { let tests = [ - // ("hello world", "Hello World"), - // ("Hello World", "Hello World"), - // ("hello_world", "Hello World"), - // ("HELLO_WORLD", "Hello World"), - // ("hello-world", "Hello World"), - // ("hello world", "Hello World"), - // (" hello world", "Hello World"), - // ("hello\tworld", "Hello World"), - // ("HELLO WORLD", "Hello World"), - // ("HELLO-world", "Hello World"), + ("hello world", "Hello World"), + ("Hello World", "Hello World"), + ("hello_world", "Hello World"), + ("HELLO_WORLD", "Hello World"), + ("hello-world", "Hello World"), + ("hello world", "Hello World"), + (" hello world", "Hello World"), + ("hello\tworld", "Hello World"), + ("HELLO WORLD", "Hello World"), + ("HELLO-world", "Hello World"), ("hello WORLD ", "Hello World"), - // ("helloWorld", "Hello World"), + ("helloWorld", "Hello World"), ]; for (input, expected) in tests {