Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `editor: convert to sentence case` (#35015)
Joseph T. Lyons913b9296d755
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rsindex f80a6afbbb0..1212651cb3f 100644--- a/crates/editor/src/actions.rs+++ b/crates/editor/src/actions.rs@@ -365,6 +365,8 @@ actions!(ConvertToLowerCase,/// Toggles the case of selected text.ConvertToOppositeCase,+ /// Converts selected text to sentence case.+ ConvertToSentenceCase,/// Converts selected text to snake_case.ConvertToSnakeCase,/// Converts selected text to Title Case.diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 069d8cffb3f..8f57fb1a206 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -10878,17 +10878,6 @@ impl Editor {});}- pub fn toggle_case(&mut self, _: &ToggleCase, window: &mut Window, cx: &mut Context<Self>) {- self.manipulate_text(window, cx, |text| {- let has_upper_case_characters = text.chars().any(|c| c.is_uppercase());- if has_upper_case_characters {- text.to_lowercase()- } else {- text.to_uppercase()- }- })- }-fn manipulate_immutable_lines<Fn>(&mut self,window: &mut Window,@@ -11144,6 +11133,26 @@ impl Editor {})}+ pub fn convert_to_sentence_case(+ &mut self,+ _: &ConvertToSentenceCase,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ self.manipulate_text(window, cx, |text| text.to_case(Case::Sentence))+ }++ pub fn toggle_case(&mut self, _: &ToggleCase, window: &mut Window, cx: &mut Context<Self>) {+ self.manipulate_text(window, cx, |text| {+ let has_upper_case_characters = text.chars().any(|c| c.is_uppercase());+ if has_upper_case_characters {+ text.to_lowercase()+ } else {+ text.to_uppercase()+ }+ })+ }+pub fn convert_to_rot13(&mut self,_: &ConvertToRot13,diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 8d121972d06..03b047e92e4 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -4724,6 +4724,23 @@ async fn test_toggle_case(cx: &mut TestAppContext) {"});}+#[gpui::test]+async fn test_convert_to_sentence_case(cx: &mut TestAppContext) {+ init_test(cx, |_| {});++ let mut cx = EditorTestContext::new(cx).await;++ cx.set_state(indoc! {"+ «implement-windows-supportˇ»+ "});+ cx.update_editor(|e, window, cx| {+ e.convert_to_sentence_case(&ConvertToSentenceCase, window, cx)+ });+ cx.assert_editor_state(indoc! {"+ «Implement windows supportˇ»+ "});+}+#[gpui::test]async fn test_manipulate_text(cx: &mut TestAppContext) {init_test(cx, |_| {});diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex d2ee9d6b0a8..5fd6b028f4e 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -230,7 +230,6 @@ impl EditorElement {register_action(editor, window, Editor::sort_lines_case_insensitive);register_action(editor, window, Editor::reverse_lines);register_action(editor, window, Editor::shuffle_lines);- register_action(editor, window, Editor::toggle_case);register_action(editor, window, Editor::convert_indentation_to_spaces);register_action(editor, window, Editor::convert_indentation_to_tabs);register_action(editor, window, Editor::convert_to_upper_case);@@ -241,6 +240,8 @@ impl EditorElement {register_action(editor, window, Editor::convert_to_upper_camel_case);register_action(editor, window, Editor::convert_to_lower_camel_case);register_action(editor, window, Editor::convert_to_opposite_case);+ register_action(editor, window, Editor::convert_to_sentence_case);+ register_action(editor, window, Editor::toggle_case);register_action(editor, window, Editor::convert_to_rot13);register_action(editor, window, Editor::convert_to_rot47);register_action(editor, window, Editor::delete_to_previous_word_start);