Delete selection in styled mode. Returns true if a selection was deleted.
(&mut self)
| 582 | |
| 583 | /// Delete selection in styled mode. Returns true if a selection was deleted. |
| 584 | pub fn delete_selection_styled(&mut self) -> bool { |
| 585 | if let Some((start, end)) = self.selection_range() { |
| 586 | if self.no_styles_movement { |
| 587 | let start_cp = styling::cursor_to_content(&self.text, start); |
| 588 | let end_cp = styling::cursor_to_content(&self.text, end); |
| 589 | if start_cp < end_cp { |
| 590 | self.text = styling::delete_content_range(&self.text, start_cp, end_cp); |
| 591 | } |
| 592 | self.cursor_pos = styling::content_to_cursor(&self.text, start_cp, true); |
| 593 | } else { |
| 594 | self.text = styling::delete_visual_range(&self.text, start, end); |
| 595 | self.cursor_pos = start; |
| 596 | } |
| 597 | self.selection_anchor = None; |
| 598 | // Cleanup empty styles (cursor is at start) |
| 599 | let (cleaned, new_pos) = styling::cleanup_empty_styles(&self.text, self.cursor_pos); |
| 600 | self.text = cleaned; |
| 601 | self.cursor_pos = new_pos; |
| 602 | self.snap_to_content_pos(); |
| 603 | // If no visible content remains after deletion, clear entirely |
| 604 | if styling::strip_styling(&self.text).is_empty() { |
| 605 | self.text = String::new(); |
| 606 | self.cursor_pos = 0; |
| 607 | } |
| 608 | true |
| 609 | } else { |
| 610 | false |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | /// Insert text at visual cursor position in styled mode, with escaping. |
| 615 | /// The input `s` should already be escaped if needed. |