(&mut self, text: &str)
| 153 | } |
| 154 | |
| 155 | pub fn insert_str(&mut self, text: &str) { |
| 156 | if text.is_empty() { |
| 157 | return; |
| 158 | } |
| 159 | let cursor_before = self.cursor; |
| 160 | let (start, deleted) = self.take_selection(); |
| 161 | let char_idx = start.unwrap_or_else(|| self.cursor_char_idx()); |
| 162 | if let Some(start) = start { |
| 163 | self.cursor = self.cursor.set_position_from_char(start, &self.document); |
| 164 | } |
| 165 | |
| 166 | self.document.insert_str(char_idx, text); |
| 167 | self.cursor = self |
| 168 | .cursor |
| 169 | .set_position_from_char(char_idx + text.chars().count(), &self.document); |
| 170 | |
| 171 | self.push_undo(UndoRecord { |
| 172 | start: char_idx, |
| 173 | inserted: text.to_owned(), |
| 174 | deleted, |
| 175 | cursor_before, |
| 176 | }); |
| 177 | } |
| 178 | |
| 179 | pub fn insert_line(&mut self, line: usize, text: &str) { |
| 180 | let cursor_before = self.cursor; |
no test coverage detected