added move start&end

imgbot
Jan Hrastnik 4 years ago committed by Blaž Hrastnik
parent 7d58378374
commit 3c0f187c5b

@ -1,6 +1,6 @@
use crate::commands;
use crate::View;
use crossterm::event::{KeyCode, KeyEvent};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::string::String;
pub struct Prompt {
@ -22,18 +22,26 @@ impl Prompt {
self.cursor_loc += 1;
}
pub fn move_char_left_prompt(&mut self) {
pub fn move_char_left(&mut self) {
if self.cursor_loc > 1 {
self.cursor_loc -= 1;
}
}
pub fn move_char_right_prompt(&mut self) {
pub fn move_char_right(&mut self) {
if self.cursor_loc < self.buffer.len() {
self.cursor_loc += 1;
}
}
pub fn move_start(&mut self) {
self.cursor_loc = 0;
}
pub fn move_end(&mut self) {
self.cursor_loc = self.buffer.len();
}
pub fn delete_char_backwards(&mut self) {
if self.cursor_loc > 0 {
self.buffer.remove(self.cursor_loc - 1);
@ -41,11 +49,15 @@ impl Prompt {
}
}
pub fn success_fn() {
// TODO:
}
pub fn handle_input(&mut self, key_event: KeyEvent, view: &mut View) {
match key_event {
KeyEvent {
code: KeyCode::Char(c),
..
modifiers: KeyModifiers::NONE,
} => self.insert_char(c),
KeyEvent {
code: KeyCode::Esc, ..
@ -53,11 +65,19 @@ impl Prompt {
KeyEvent {
code: KeyCode::Right,
..
} => self.move_char_right_prompt(),
} => self.move_char_right(),
KeyEvent {
code: KeyCode::Left,
..
} => self.move_char_left_prompt(),
} => self.move_char_left(),
KeyEvent {
code: KeyCode::Char('e'),
modifiers: KeyModifiers::CONTROL,
} => self.move_end(),
KeyEvent {
code: KeyCode::Char('a'),
modifiers: KeyModifiers::CONTROL,
} => self.move_start(),
KeyEvent {
code: KeyCode::Backspace,
..

Loading…
Cancel
Save