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
1649 "theme",1649 "theme",
1650]1650]
1651 1651
1652[[package]]
1653name = "convert_case"
1654version = "0.6.0"
1655source = "registry+https://github.com/rust-lang/crates.io-index"
1656checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
1657dependencies = [
1658 "unicode-segmentation",
1659]
1660
1652[[package]]1661[[package]]
1653name = "copilot"1662name = "copilot"
1654version = "0.1.0"1663version = "0.1.0"
@@ -2314,6 +2323,7 @@ dependencies = [ · 659 unmodified lines
2314 "clock",2323 "clock",
2315 "collections",2324 "collections",
2316 "context_menu",2325 "context_menu",
2326 "convert_case",
2317 "copilot",2327 "copilot",
2318 "ctor",2328 "ctor",
2319 "db",2329 "db",
crates/editor/Cargo.toml+2−1
@@ -47,6 +47,7 @@ workspace = { path = "../workspace" } · 46 unmodified lines
47 47
48aho-corasick = "0.7"48aho-corasick = "0.7"
49anyhow.workspace = true49anyhow.workspace = true
50convert_case = "0.6.0"
50futures.workspace = true51futures.workspace = true
51indoc = "1.0.4"52indoc = "1.0.4"
52itertools = "0.10"53itertools = "0.10"
@@ -56,12 +57,12 @@ ordered-float.workspace = true · 3 unmodified lines
56parking_lot.workspace = true57parking_lot.workspace = true
57postage.workspace = true58postage.workspace = true
58pulldown-cmark = { version = "0.9.2", default-features = false }59pulldown-cmark = { version = "0.9.2", default-features = false }
60rand.workspace = true
59schemars.workspace = true61schemars.workspace = true
60serde.workspace = true62serde.workspace = true
61serde_derive.workspace = true63serde_derive.workspace = true
62smallvec.workspace = true64smallvec.workspace = true
63smol.workspace = true65smol.workspace = true
64rand.workspace = true
65 66
66tree-sitter-rust = { workspace = true, optional = true }67tree-sitter-rust = { workspace = true, optional = true }
67tree-sitter-html = { workspace = true, optional = true }68tree-sitter-html = { workspace = true, optional = true }
crates/editor/src/editor.rs+39−0
@@ -28,6 +28,7 @@ use blink_manager::BlinkManager; · 27 unmodified lines
28use client::{ClickhouseEvent, TelemetrySettings};28use client::{ClickhouseEvent, TelemetrySettings};
29use clock::{Global, ReplicaId};29use clock::{Global, ReplicaId};
30use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};30use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
31use convert_case::{Case, Casing};
31use copilot::Copilot;32use copilot::Copilot;
32pub use display_map::DisplayPoint;33pub use display_map::DisplayPoint;
33use display_map::*;34use display_map::*;
@@ -233,6 +234,11 @@ actions!( · 199 unmodified lines
233 ShuffleLines,234 ShuffleLines,
234 ConvertToUpperCase,235 ConvertToUpperCase,
235 ConvertToLowerCase,236 ConvertToLowerCase,
237 ConvertToTitleCase,
238 ConvertToSnakeCase,
239 ConvertToKebabCase,
240 ConvertToUpperCamelCase,
241 ConvertToLowerCamelCase,
236 Transpose,242 Transpose,
237 Cut,243 Cut,
238 Copy,244 Copy,
@@ -357,6 +363,11 @@ pub fn init(cx: &mut AppContext) { · 118 unmodified lines
357 cx.add_action(Editor::shuffle_lines);363 cx.add_action(Editor::shuffle_lines);
358 cx.add_action(Editor::convert_to_upper_case);364 cx.add_action(Editor::convert_to_upper_case);
359 cx.add_action(Editor::convert_to_lower_case);365 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);
360 cx.add_action(Editor::delete_to_previous_word_start);371 cx.add_action(Editor::delete_to_previous_word_start);
361 cx.add_action(Editor::delete_to_previous_subword_start);372 cx.add_action(Editor::delete_to_previous_subword_start);
362 cx.add_action(Editor::delete_to_next_word_end);373 cx.add_action(Editor::delete_to_next_word_end);
@@ -4318,6 +4329,34 @@ impl Editor { · 3955 unmodified lines
4318 self.manipulate_text(cx, |text| text.to_lowercase())4329 self.manipulate_text(cx, |text| text.to_lowercase())
4319 }4330 }
4320 4331
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
4321 fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)4360 fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)
4322 where4361 where
4323 Fn: FnMut(&str) -> String,4362 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