cleanup
This commit is contained in:
parent
a5ce49576b
commit
eb9ab8f85b
1 changed files with 20 additions and 35 deletions
|
@ -130,20 +130,7 @@ impl Editor {
|
|||
|
||||
/// Cursor movement logic, returns true if cursor moved (so consider the event consumed in that case)
|
||||
fn input_movement(&mut self, event: &KeyEvent) -> bool {
|
||||
if let KeyCode::Left
|
||||
| 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 prev_pos = self.char_index();
|
||||
let height = terminal::size().unwrap().1 as usize;
|
||||
match event.code {
|
||||
KeyCode::Left => self.move_left(),
|
||||
|
@ -154,12 +141,16 @@ impl Editor {
|
|||
KeyCode::PageDown => self.move_down(height),
|
||||
KeyCode::Home => self.move_home(),
|
||||
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
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
fn ensure_char_boundary(&mut self) {
|
||||
while !self
|
||||
|
|
Loading…
Reference in a new issue