| 177 | } |
| 178 | |
| 179 | pub fn insert_line(&mut self, line: usize, text: &str) { |
| 180 | let cursor_before = self.cursor; |
| 181 | let char_idx = if line >= self.line_count() { |
| 182 | self.document.len_chars() |
| 183 | } else { |
| 184 | self.document.line_to_char(line) |
| 185 | }; |
| 186 | self.document.insert_line(line, text); |
| 187 | self.cursor.clamp_to_document(&self.document); |
| 188 | let inserted = format!("{text}\n"); |
| 189 | self.push_undo(UndoRecord { |
| 190 | start: char_idx, |
| 191 | inserted, |
| 192 | deleted: String::new(), |
| 193 | cursor_before, |
| 194 | }); |
| 195 | } |
| 196 | |
| 197 | pub fn delete_line(&mut self, line: usize) { |
| 198 | if line >= self.line_count() { |