Add convert to opposite case
command (#11290)
This commit is contained in:
parent
092869d1fa
commit
98ea5e172e
4 changed files with 31 additions and 3 deletions
|
@ -5192,6 +5192,24 @@ impl Editor {
|
|||
self.manipulate_text(cx, |text| text.to_case(Case::Camel))
|
||||
}
|
||||
|
||||
pub fn convert_to_opposite_case(
|
||||
&mut self,
|
||||
_: &ConvertToOppositeCase,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.manipulate_text(cx, |text| {
|
||||
text.chars()
|
||||
.fold(String::with_capacity(text.len()), |mut t, c| {
|
||||
if c.is_uppercase() {
|
||||
t.extend(c.to_lowercase());
|
||||
} else {
|
||||
t.extend(c.to_uppercase());
|
||||
}
|
||||
t
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn manipulate_text<Fn>(&mut self, cx: &mut ViewContext<Self>, mut callback: Fn)
|
||||
where
|
||||
Fn: FnMut(&str) -> String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue