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

View file

@ -130,20 +130,7 @@ 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
| KeyCode::Up
| KeyCode::Down
| KeyCode::Home
| KeyCode::PageUp
| KeyCode::PageDown
| KeyCode::End = event.code
{
if event.modifiers.contains(KeyModifiers::SHIFT) {
self.set_marker();
} else {
self.marker = None;
}
let height = terminal::size().unwrap().1 as usize; let height = terminal::size().unwrap().1 as usize;
match event.code { match event.code {
KeyCode::Left => self.move_left(), KeyCode::Left => self.move_left(),
@ -154,12 +141,16 @@ impl Editor {
KeyCode::PageDown => self.move_down(height), KeyCode::PageDown => self.move_down(height),
KeyCode::Home => self.move_home(), KeyCode::Home => self.move_home(),
KeyCode::End => self.move_end(), KeyCode::End => self.move_end(),
_ => (), _ => return false,
}
if event.modifiers.contains(KeyModifiers::SHIFT) {
if self.marker.is_none() {
self.marker = Some(prev_pos);
}
} else {
self.marker = None;
} }
true true
} else {
false
}
} }
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