MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / insert_text_styled

Method insert_text_styled

src/text_input.rs:616–647  ·  view source on GitHub ↗

Insert text at visual cursor position in styled mode, with escaping. The input `s` should already be escaped if needed.

(&mut self, s: &str, max_length: Option<usize>)

Source from the content-addressed store, hash-verified

614 /// Insert text at visual cursor position in styled mode, with escaping.
615 /// The input `s` should already be escaped if needed.
616 pub fn insert_text_styled(&mut self, s: &str, max_length: Option<usize>) {
617 self.delete_selection_styled();
618 let visual_count = self.cursor_len_styled();
619 let insert_cursor_len = styling::cursor_len(s);
620 let allowed = if let Some(max) = max_length {
621 if visual_count >= max {
622 0
623 } else {
624 insert_cursor_len.min(max - visual_count)
625 }
626 } else {
627 insert_cursor_len
628 };
629 if allowed == 0 {
630 return;
631 }
632 // If we need to truncate the insertion, work on the visual chars
633 let insert_str = if allowed < insert_cursor_len {
634 // Build truncated escaped string
635 let stripped = styling::strip_styling(s);
636 let truncated: String = stripped.chars().take(allowed).collect();
637 styling::escape_str(&truncated)
638 } else {
639 s.to_string()
640 };
641 let (new_text, new_cursor) = styling::insert_at_visual(&self.text, self.cursor_pos, &insert_str);
642 self.text = new_text;
643 self.cursor_pos = new_cursor;
644 // Clean up any empty style tags the cursor has passed
645 self.cleanup_after_move();
646 self.reset_blink();
647 }
648
649 /// Insert a single typed character in styled mode (auto-escapes).
650 pub fn insert_char_styled(&mut self, ch: char, max_length: Option<usize>) {

Callers 2

insert_char_styledMethod · 0.80

Calls 8

cursor_lenFunction · 0.85
strip_stylingFunction · 0.85
escape_strFunction · 0.85
insert_at_visualFunction · 0.85
cursor_len_styledMethod · 0.80
cleanup_after_moveMethod · 0.80
reset_blinkMethod · 0.80

Tested by

no test coverage detected