Move cursor left by one character.
(&mut self, shift: bool)
| 145 | |
| 146 | /// Move cursor left by one character. |
| 147 | pub fn move_left(&mut self, shift: bool) { |
| 148 | if !shift { |
| 149 | // If there's a selection and no shift, collapse to start |
| 150 | if let Some((start, _end)) = self.selection_range() { |
| 151 | self.cursor_pos = start; |
| 152 | self.selection_anchor = None; |
| 153 | self.reset_blink(); |
| 154 | return; |
| 155 | } |
| 156 | } |
| 157 | if self.cursor_pos > 0 { |
| 158 | if shift && self.selection_anchor.is_none() { |
| 159 | self.selection_anchor = Some(self.cursor_pos); |
| 160 | } |
| 161 | self.cursor_pos -= 1; |
| 162 | if shift { |
| 163 | // If anchor equals cursor, clear selection |
| 164 | if self.selection_anchor == Some(self.cursor_pos) { |
| 165 | self.selection_anchor = None; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | if !shift { |
| 170 | self.selection_anchor = None; |
| 171 | } |
| 172 | self.reset_blink(); |
| 173 | } |
| 174 | |
| 175 | /// Move cursor right by one character. |
| 176 | pub fn move_right(&mut self, shift: bool) { |