This commit is contained in:
Crispy 2023-03-14 13:46:28 +01:00
parent a5ce49576b
commit eb9ab8f85b

View file

@ -130,36 +130,27 @@ impl Editor {
/// Cursor movement logic, returns true if cursor moved (so consider the event consumed in that case) /// Cursor movement logic, returns true if cursor moved (so consider the event consumed in that case)
fn input_movement(&mut self, event: &KeyEvent) -> bool { fn input_movement(&mut self, event: &KeyEvent) -> bool {
if let KeyCode::Left let prev_pos = self.char_index();
| KeyCode::Right let height = terminal::size().unwrap().1 as usize;
| KeyCode::Up match event.code {
| KeyCode::Down KeyCode::Left => self.move_left(),
| KeyCode::Home KeyCode::Right => self.move_right(),
| KeyCode::PageUp KeyCode::Up => self.move_up(1),
| KeyCode::PageDown KeyCode::Down => self.move_down(1),
| KeyCode::End = event.code KeyCode::PageUp => self.move_up(height),
{ KeyCode::PageDown => self.move_down(height),
if event.modifiers.contains(KeyModifiers::SHIFT) { KeyCode::Home => self.move_home(),
self.set_marker(); KeyCode::End => self.move_end(),
} else { _ => return false,
self.marker = None;
}
let height = terminal::size().unwrap().1 as usize;
match event.code {
KeyCode::Left => self.move_left(),
KeyCode::Right => self.move_right(),
KeyCode::Up => self.move_up(1),
KeyCode::Down => self.move_down(1),
KeyCode::PageUp => self.move_up(height),
KeyCode::PageDown => self.move_down(height),
KeyCode::Home => self.move_home(),
KeyCode::End => self.move_end(),
_ => (),
}
true
} else {
false
} }
if event.modifiers.contains(KeyModifiers::SHIFT) {
if self.marker.is_none() {
self.marker = Some(prev_pos);
}
} else {
self.marker = None;
}
true
} }
fn draw(&self) { fn draw(&self) {
@ -296,12 +287,6 @@ impl Editor {
} }
} }
fn set_marker(&mut self) {
if self.marker.is_none() {
self.marker = Some(self.char_index());
}
}
/// Moves cursor left until it is on a character (in case it was in the middle of a multi-byte character) /// Moves cursor left until it is on a character (in case it was in the middle of a multi-byte character)
fn ensure_char_boundary(&mut self) { fn ensure_char_boundary(&mut self) {
while !self while !self