make delete selection public

This commit is contained in:
Evan Almloff committed 2023-01-20 17:16:47 -06:00
1 parent 8030ae5581
commit d019ada3da
1 file changed
+2 -8
+2 -8
View File
@@ -206,22 +206,16 @@ impl Cursor {
} }
} }
fn delete_selection<T: Text + ?Sized>(&mut self, text: &mut impl TextEditable<T>) -> [i32; 2] { /// Delete the currently selected text and update the cursor position.
pub fn delete_selection<T: Text + ?Sized>(&mut self, text: &mut impl TextEditable<T>) {
let first = self.first(); let first = self.first();
let last = self.last(); let last = self.last();
let dr = first.row as i32 - last.row as i32;
let dc = if dr != 0 {
-(last.col as i32)
} else {
first.col as i32 - last.col as i32
};
text.delete_range(first.idx(text.as_ref())..last.idx(text.as_ref())); text.delete_range(first.idx(text.as_ref())..last.idx(text.as_ref()));
if let Some(end) = self.end.take() { if let Some(end) = self.end.take() {
if self.start > end { if self.start > end {
self.start = end; self.start = end;
} }
} }
[dc, dr]
} }
/// Handle moving the cursor with the given key. /// Handle moving the cursor with the given key.