Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add more convert to case commands
Joseph T. Lyons12e8f417e4ca
diff --git a/Cargo.lock b/Cargo.lockindex fbf4e750c62..5afa1ebe625 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1649,6 +1649,15 @@ dependencies = ["theme",]+[[package]]+name = "convert_case"+version = "0.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"+dependencies = [+ "unicode-segmentation",+]+[[package]]name = "copilot"version = "0.1.0"@@ -2314,6 +2323,7 @@ dependencies = ["clock","collections","context_menu",+ "convert_case","copilot","ctor","db",diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.tomlindex bc1c9044049..2fdeee56c18 100644--- a/crates/editor/Cargo.toml+++ b/crates/editor/Cargo.toml@@ -47,6 +47,7 @@ workspace = { path = "../workspace" }aho-corasick = "0.7"anyhow.workspace = true+convert_case = "0.6.0"futures.workspace = trueindoc = "1.0.4"itertools = "0.10"@@ -56,12 +57,12 @@ ordered-float.workspace = trueparking_lot.workspace = truepostage.workspace = truepulldown-cmark = { version = "0.9.2", default-features = false }+rand.workspace = trueschemars.workspace = trueserde.workspace = trueserde_derive.workspace = truesmallvec.workspace = truesmol.workspace = true-rand.workspace = truetree-sitter-rust = { workspace = true, optional = true }tree-sitter-html = { workspace = true, optional = true }diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex ab952ba6e72..c70a1a8e048 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -28,6 +28,7 @@ use blink_manager::BlinkManager;use client::{ClickhouseEvent, TelemetrySettings};use clock::{Global, ReplicaId};use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};+use convert_case::{Case, Casing};use copilot::Copilot;pub use display_map::DisplayPoint;use display_map::*;@@ -233,6 +234,11 @@ actions!(ShuffleLines,ConvertToUpperCase,ConvertToLowerCase,+ ConvertToTitleCase,+ ConvertToSnakeCase,+ ConvertToKebabCase,+ ConvertToUpperCamelCase,+ ConvertToLowerCamelCase,Transpose,Cut,Copy,@@ -357,6 +363,11 @@ pub fn init(cx: &mut AppContext) {cx.add_action(Editor::shuffle_lines);cx.add_action(Editor::convert_to_upper_case);cx.add_action(Editor::convert_to_lower_case);+ cx.add_action(Editor::convert_to_title_case);+ cx.add_action(Editor::convert_to_snake_case);+ cx.add_action(Editor::convert_to_kebab_case);+ cx.add_action(Editor::convert_to_upper_camel_case);+ cx.add_action(Editor::convert_to_lower_camel_case);cx.add_action(Editor::delete_to_previous_word_start);cx.add_action(Editor::delete_to_previous_subword_start);cx.add_action(Editor::delete_to_next_word_end);@@ -4318,6 +4329,34 @@ impl Editor {self.manipulate_text(cx, |text| text.to_lowercase())}+ pub fn convert_to_title_case(&mut self, _: &ConvertToTitleCase, cx: &mut ViewContext<Self>) {+ self.manipulate_text(cx, |text| text.to_case(Case::Title))+ }++ pub fn convert_to_snake_case(&mut self, _: &ConvertToSnakeCase, cx: &mut ViewContext<Self>) {+ self.manipulate_text(cx, |text| text.to_case(Case::Snake))+ }++ pub fn convert_to_kebab_case(&mut self, _: &ConvertToKebabCase, cx: &mut ViewContext<Self>) {+ self.manipulate_text(cx, |text| text.to_case(Case::Kebab))+ }++ pub fn convert_to_upper_camel_case(+ &mut self,+ _: &ConvertToUpperCamelCase,+ cx: &mut ViewContext<Self>,+ ) {+ self.manipulate_text(cx, |text| text.to_case(Case::UpperCamel))+ }++ pub fn convert_to_lower_camel_case(+ &mut self,+ _: &ConvertToLowerCamelCase,+ cx: &mut ViewContext<Self>,+ ) {+ self.manipulate_text(cx, |text| text.to_case(Case::Camel))+ }+fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)whereFn: FnMut(&str) -> String,