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

Method insert_text

src/text_input.rs:123–144  ·  view source on GitHub ↗

Insert text at the current cursor position, replacing any selection. Respects max_length if provided.

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

Source from the content-addressed store, hash-verified

121 /// Insert text at the current cursor position, replacing any selection.
122 /// Respects max_length if provided.
123 pub fn insert_text(&mut self, s: &str, max_length: Option<usize>) {
124 self.delete_selection();
125 let char_count = self.text.chars().count();
126 let insert_count = s.chars().count();
127 let allowed = if let Some(max) = max_length {
128 if char_count >= max {
129 0
130 } else {
131 insert_count.min(max - char_count)
132 }
133 } else {
134 insert_count
135 };
136 if allowed == 0 {
137 return;
138 }
139 let insert_str: String = s.chars().take(allowed).collect();
140 let byte_pos = char_index_to_byte(&self.text, self.cursor_pos);
141 self.text.insert_str(byte_pos, &insert_str);
142 self.cursor_pos += allowed;
143 self.reset_blink();
144 }
145
146 /// Move cursor left by one character.
147 pub fn move_left(&mut self, shift: bool) {

Calls 3

char_index_to_byteFunction · 0.85
delete_selectionMethod · 0.80
reset_blinkMethod · 0.80

Tested by 6

test_insert_textFunction · 0.64
test_undo_basicFunction · 0.64