| 130 | } |
| 131 | |
| 132 | pub fn insert_char(&mut self, ch: char) { |
| 133 | let cursor_before = self.cursor; |
| 134 | let (start, deleted) = self.take_selection(); |
| 135 | let char_idx = start.unwrap_or_else(|| self.cursor_char_idx()); |
| 136 | if let Some(start) = start { |
| 137 | self.cursor = self.cursor.set_position_from_char(start, &self.document); |
| 138 | } |
| 139 | |
| 140 | self.document.insert_char(char_idx, ch); |
| 141 | self.cursor = self.cursor.set_position_from_char(char_idx + 1, &self.document); |
| 142 | |
| 143 | self.push_undo(UndoRecord { |
| 144 | start: char_idx, |
| 145 | inserted: ch.to_string(), |
| 146 | deleted, |
| 147 | cursor_before, |
| 148 | }); |
| 149 | } |
| 150 | |
| 151 | pub fn insert_newline(&mut self) { |
| 152 | self.insert_char('\n'); |