Make text uppercase/lowercase using general transform_text function
@@ -961,27 +961,13 @@ impl Editor {
self.view.collapse_selections(&self.text);
}
- fn make_uppercase(&mut self) {
+ fn transform_text(&mut self, transform_function: &Fn(String) -> String) {
let mut builder = delta::Builder::new(self.text.len());
for region in self.view.sel_regions() {
let selected_text = self.text.slice_to_string(region.min(), region.max());
let interval = Interval::new_closed_open(region.min(), region.max());
- builder.replace(interval, Rope::from(selected_text.to_uppercase()));
- }
- if !builder.is_empty() {
- self.this_edit_type = EditType::Other;
- self.add_delta(builder.build());
- }
- }
-
- fn make_lowercase(&mut self) {
- let mut builder = delta::Builder::new(self.text.len());
-
- for region in self.view.sel_regions() {
- let selected_text = self.text.slice_to_string(region.min(), region.max());
- let interval = Interval::new_closed_open(region.min(), region.max());
- builder.replace(interval, Rope::from(selected_text.to_lowercase()));
+ builder.replace(interval, Rope::from(transform_function(selected_text)));
}
if !builder.is_empty() {
self.this_edit_type = EditType::Other;
@@ -1066,8 +1052,8 @@ impl Editor {
DebugRewrap => self.debug_rewrap(),
DebugPrintSpans => self.debug_print_spans(),
CancelOperation => self.do_cancel_operation(),
- Uppercase => self.make_uppercase(),
- Lowercase => self.make_lowercase(),
+ Uppercase => self.transform_text(&|s| s.to_uppercase()),
+ Lowercase => self.transform_text(&|s| s.to_lowercase()),
};
self.cmd_postlude();
