feat: add commands for working with different cases

pull/12043/head
Nikita Revenco 2024-11-09 16:32:22 +00:00 committed by Nikita Revenco
parent 0efa8207d8
commit d0a3ae8a90
4 changed files with 40 additions and 5 deletions

1
Cargo.lock generated
View File

@ -1469,6 +1469,7 @@ dependencies = [
"futures-util", "futures-util",
"grep-regex", "grep-regex",
"grep-searcher", "grep-searcher",
"heck",
"helix-core", "helix-core",
"helix-dap", "helix-dap",
"helix-event", "helix-event",

View File

@ -53,6 +53,7 @@ helix-loader = { path = "../helix-loader" }
anyhow = "1" anyhow = "1"
once_cell = "1.20" once_cell = "1.20"
heck = "0.5"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] }
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] } tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
crossterm = { version = "0.28", features = ["event-stream"] } crossterm = { version = "0.28", features = ["event-stream"] }

View File

@ -54,6 +54,7 @@ use helix_view::{
}; };
use anyhow::{anyhow, bail, ensure, Context as _}; use anyhow::{anyhow, bail, ensure, Context as _};
use heck::{ToKebabCase, ToLowerCamelCase, ToSnakeCase, ToTitleCase, ToUpperCamelCase};
use insert::*; use insert::*;
use movement::Movement; use movement::Movement;
@ -352,9 +353,14 @@ impl MappableCommand {
extend_prev_char, "Extend to previous occurrence of char", extend_prev_char, "Extend to previous occurrence of char",
repeat_last_motion, "Repeat last motion", repeat_last_motion, "Repeat last motion",
replace, "Replace with new char", replace, "Replace with new char",
switch_case, "Switch (toggle) case", switch_to_alternate_case, "Switch to aLTERNATE cASE",
switch_to_uppercase, "Switch to uppercase", switch_to_uppercase, "Switch to UPPERCASE",
switch_to_lowercase, "Switch to lowercase", switch_to_lowercase, "Switch to lowercase",
switch_to_pascal_case, "Switch to PascalCase",
switch_to_camel_case, "Switch to camelCase",
switch_to_title_case, "Switch to Title Case",
switch_to_snake_case, "Switch to snake_case",
switch_to_kebab_case, "Switch to kebab-case",
page_up, "Move page up", page_up, "Move page up",
page_down, "Move page down", page_down, "Move page down",
half_page_up, "Move half page up", half_page_up, "Move half page up",
@ -1773,6 +1779,26 @@ fn switch_case(cx: &mut Context) {
}); });
} }
fn switch_to_pascal_case(cx: &mut Context) {
switch_heck_case_impl(cx, |str| str.to_upper_camel_case())
}
fn switch_to_camel_case(cx: &mut Context) {
switch_heck_case_impl(cx, |str| str.to_lower_camel_case())
}
fn switch_to_title_case(cx: &mut Context) {
switch_heck_case_impl(cx, |str| str.to_title_case())
}
fn switch_to_snake_case(cx: &mut Context) {
switch_heck_case_impl(cx, |str| str.to_snake_case())
}
fn switch_to_kebab_case(cx: &mut Context) {
switch_heck_case_impl(cx, |str| str.to_kebab_case())
}
fn switch_to_uppercase(cx: &mut Context) { fn switch_to_uppercase(cx: &mut Context) {
switch_case_impl(cx, |string| { switch_case_impl(cx, |string| {
string.chunks().map(|chunk| chunk.to_uppercase()).collect() string.chunks().map(|chunk| chunk.to_uppercase()).collect()

View File

@ -19,9 +19,16 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"R" => replace_with_yanked, "R" => replace_with_yanked,
"A-." => repeat_last_motion, "A-." => repeat_last_motion,
"~" => switch_case, "~" => switch_to_alternate_case,
"`" => switch_to_lowercase, "`" => { "Case"
"A-`" => switch_to_uppercase, "l" => switch_to_lowercase,
"u" => switch_to_uppercase,
"p" => switch_to_pascal_case,
"c" => switch_to_camel_case,
"t" => switch_to_title_case,
"s" => switch_to_snake_case,
"k" => switch_to_kebab_case,
},
"home" => goto_line_start, "home" => goto_line_start,
"end" => goto_line_end, "end" => goto_line_end,