Add convert to opposite case command (#11290)

This commit is contained in:
Joseph T. Lyons 2024-05-02 08:37:13 -04:00 committed by GitHub
parent 092869d1fa
commit 98ea5e172e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 3 deletions

View file

@ -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,