Returns the selected text, or empty string if no selection.
(&self)
| 94 | |
| 95 | /// Returns the selected text, or empty string if no selection. |
| 96 | pub fn selected_text(&self) -> &str { |
| 97 | if let Some((start, end)) = self.selection_range() { |
| 98 | let byte_start = char_index_to_byte(&self.text, start); |
| 99 | let byte_end = char_index_to_byte(&self.text, end); |
| 100 | &self.text[byte_start..byte_end] |
| 101 | } else { |
| 102 | "" |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /// Delete the current selection and place cursor at the start. |
| 107 | /// Returns true if a selection was deleted. |
no test coverage detected