History

Add more convert to case commands (#2825)

I'm using [convert_case](https://crates.io/crates/convert_case) underneath the hood, which has over 35 million downloads and feels solid. Release Notes: - Added commands to convert between variable name styles ([#1821](https://github.com/zed-industries/community/issues/1821)). - `convert to kebab case` - `convert to snake case` - `convert to upper camel case` - `convert to lower camel case` - `convert to title case`

Joseph T. Lyons committed 3 years ago

Commit d1048d02 parents 5c2f38a 12e8f413 files · +51 −1Browse files

Unified · Split

3 files
  1. Cargo.lock +10 −0
  2. crates/editor/Cargo.toml +2 −1
  3. crates/editor/src/editor.rs +39 −0
Cargo.lock+10−0
@@ -1649,6 +1649,15 @@ dependencies = [ · 1648 unmodified lines
16491649 "theme",
16501650 ]
16511651
1652+[[package]]
1653+name = "convert_case"
1654+version = "0.6.0"
1655+source = "registry+https://github.com/rust-lang/crates.io-index"
1656+checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
1657+dependencies = [
1658+ "unicode-segmentation",
1659+]
1660+
16521661 [[package]]
16531662 name = "copilot"
16541663 version = "0.1.0"
@@ -2314,6 +2323,7 @@ dependencies = [ · 659 unmodified lines
23142323 "clock",
23152324 "collections",
23162325 "context_menu",
2326+ "convert_case",
23172327 "copilot",
23182328 "ctor",
23192329 "db",
crates/editor/Cargo.toml+2−1
@@ -47,6 +47,7 @@ workspace = { path = "../workspace" } · 46 unmodified lines
4747
4848 aho-corasick = "0.7"
4949 anyhow.workspace = true
50+convert_case = "0.6.0"
5051 futures.workspace = true
5152 indoc = "1.0.4"
5253 itertools = "0.10"
@@ -56,12 +57,12 @@ ordered-float.workspace = true · 3 unmodified lines
5657 parking_lot.workspace = true
5758 postage.workspace = true
5859 pulldown-cmark = { version = "0.9.2", default-features = false }
60+rand.workspace = true
5961 schemars.workspace = true
6062 serde.workspace = true
6163 serde_derive.workspace = true
6264 smallvec.workspace = true
6365 smol.workspace = true
64−rand.workspace = true
6566
6667 tree-sitter-rust = { workspace = true, optional = true }
6768 tree-sitter-html = { workspace = true, optional = true }
crates/editor/src/editor.rs+39−0
@@ -28,6 +28,7 @@ use blink_manager::BlinkManager; · 27 unmodified lines
2828 use client::{ClickhouseEvent, TelemetrySettings};
2929 use clock::{Global, ReplicaId};
3030 use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
31+use convert_case::{Case, Casing};
3132 use copilot::Copilot;
3233 pub use display_map::DisplayPoint;
3334 use display_map::*;
@@ -233,6 +234,11 @@ actions!( · 199 unmodified lines
233234 ShuffleLines,
234235 ConvertToUpperCase,
235236 ConvertToLowerCase,
237+ ConvertToTitleCase,
238+ ConvertToSnakeCase,
239+ ConvertToKebabCase,
240+ ConvertToUpperCamelCase,
241+ ConvertToLowerCamelCase,
236242 Transpose,
237243 Cut,
238244 Copy,
@@ -357,6 +363,11 @@ pub fn init(cx: &mut AppContext) { · 118 unmodified lines
357363 cx.add_action(Editor::shuffle_lines);
358364 cx.add_action(Editor::convert_to_upper_case);
359365 cx.add_action(Editor::convert_to_lower_case);
366+ cx.add_action(Editor::convert_to_title_case);
367+ cx.add_action(Editor::convert_to_snake_case);
368+ cx.add_action(Editor::convert_to_kebab_case);
369+ cx.add_action(Editor::convert_to_upper_camel_case);
370+ cx.add_action(Editor::convert_to_lower_camel_case);
360371 cx.add_action(Editor::delete_to_previous_word_start);
361372 cx.add_action(Editor::delete_to_previous_subword_start);
362373 cx.add_action(Editor::delete_to_next_word_end);
@@ -4318,6 +4329,34 @@ impl Editor { · 3955 unmodified lines
43184329 self.manipulate_text(cx, |text| text.to_lowercase())
43194330 }
43204331
4332+ pub fn convert_to_title_case(&mut self, _: &ConvertToTitleCase, cx: &mut ViewContext<Self>) {
4333+ self.manipulate_text(cx, |text| text.to_case(Case::Title))
4334+ }
4335+
4336+ pub fn convert_to_snake_case(&mut self, _: &ConvertToSnakeCase, cx: &mut ViewContext<Self>) {
4337+ self.manipulate_text(cx, |text| text.to_case(Case::Snake))
4338+ }
4339+
4340+ pub fn convert_to_kebab_case(&mut self, _: &ConvertToKebabCase, cx: &mut ViewContext<Self>) {
4341+ self.manipulate_text(cx, |text| text.to_case(Case::Kebab))
4342+ }
4343+
4344+ pub fn convert_to_upper_camel_case(
4345+ &mut self,
4346+ _: &ConvertToUpperCamelCase,
4347+ cx: &mut ViewContext<Self>,
4348+ ) {
4349+ self.manipulate_text(cx, |text| text.to_case(Case::UpperCamel))
4350+ }
4351+
4352+ pub fn convert_to_lower_camel_case(
4353+ &mut self,
4354+ _: &ConvertToLowerCamelCase,
4355+ cx: &mut ViewContext<Self>,
4356+ ) {
4357+ self.manipulate_text(cx, |text| text.to_case(Case::Camel))
4358+ }
4359+
43214360 fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)
43224361 where
43234362 Fn: FnMut(&str) -> String,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t