Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix text transformation commands for multiple line, single selection cases (#3060)
Joseph T. Lyons3cf7164a5406
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex ff34fea917f..0facf0d7911 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -4653,7 +4653,13 @@ impl Editor {}pub fn convert_to_title_case(&mut self, _: &ConvertToTitleCase, cx: &mut ViewContext<Self>) {- self.manipulate_text(cx, |text| text.to_case(Case::Title))+ self.manipulate_text(cx, |text| {+ // Hack to get around the fact that to_case crate doesn't support '\n' as a word boundary+ // https://github.com/rutrum/convert-case/issues/16+ text.split("\n")+ .map(|line| line.to_case(Case::Title))+ .join("\n")+ })}pub fn convert_to_snake_case(&mut self, _: &ConvertToSnakeCase, cx: &mut ViewContext<Self>) {@@ -4669,7 +4675,13 @@ impl Editor {_: &ConvertToUpperCamelCase,cx: &mut ViewContext<Self>,) {- self.manipulate_text(cx, |text| text.to_case(Case::UpperCamel))+ self.manipulate_text(cx, |text| {+ // Hack to get around the fact that to_case crate doesn't support '\n' as a word boundary+ // https://github.com/rutrum/convert-case/issues/16+ text.split("\n")+ .map(|line| line.to_case(Case::UpperCamel))+ .join("\n")+ })}pub fn convert_to_lower_camel_case(diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 72df7b78741..dee27e01212 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -2792,6 +2792,34 @@ async fn test_manipulate_text(cx: &mut TestAppContext) {«hello worldˇ»"});+ // Test multiple line, single selection case+ // Test code hack that covers the fact that to_case crate doesn't support '\n' as a word boundary+ cx.set_state(indoc! {"+ «The quick brown+ fox jumps over+ the lazy dogˇ»+ "});+ cx.update_editor(|e, cx| e.convert_to_title_case(&ConvertToTitleCase, cx));+ cx.assert_editor_state(indoc! {"+ «The Quick Brown+ Fox Jumps Over+ The Lazy Dogˇ»+ "});++ // Test multiple line, single selection case+ // Test code hack that covers the fact that to_case crate doesn't support '\n' as a word boundary+ cx.set_state(indoc! {"+ «The quick brown+ fox jumps over+ the lazy dogˇ»+ "});+ cx.update_editor(|e, cx| e.convert_to_upper_camel_case(&ConvertToUpperCamelCase, cx));+ cx.assert_editor_state(indoc! {"+ «TheQuickBrown+ FoxJumpsOver+ TheLazyDogˇ»+ "});+// From here on out, test more complex cases of manipulate_text()// Test no selection case - should affect words cursors are in