Add toggle case command (#28415)
A small addition for those coming from JetBrain's IDEs. A behavioral detail: when any upper case character is detected, the command defaults to toggling to lower case. > Note that when you apply the toggle case action to the CamelCase name format, IntelliJ IDEA converts the name to the lower case. https://www.jetbrains.com/help/idea/working-with-source-code.html#edit_code_fragments Release Notes: - Added an `editor: toggle case` command. Use `cmd-shift-u` for macOS and `ctrl-shift-u` for Linux, when using the `JetBrains` keymap.
This commit is contained in:
parent
c441b651fa
commit
31034f8296
6 changed files with 52 additions and 2 deletions
|
@ -9143,6 +9143,17 @@ 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()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn convert_to_upper_case(
|
||||
&mut self,
|
||||
_: &ConvertToUpperCase,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue