Delete the current selection and place cursor at the start. Returns true if a selection was deleted.
(&mut self)
| 106 | /// Delete the current selection and place cursor at the start. |
| 107 | /// Returns true if a selection was deleted. |
| 108 | pub fn delete_selection(&mut self) -> bool { |
| 109 | if let Some((start, end)) = self.selection_range() { |
| 110 | let byte_start = char_index_to_byte(&self.text, start); |
| 111 | let byte_end = char_index_to_byte(&self.text, end); |
| 112 | self.text.drain(byte_start..byte_end); |
| 113 | self.cursor_pos = start; |
| 114 | self.selection_anchor = None; |
| 115 | true |
| 116 | } else { |
| 117 | false |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /// Insert text at the current cursor position, replacing any selection. |
| 122 | /// Respects max_length if provided. |