From 3c0f187c5bd24b0af7699cf813a151088b2217d0 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Tue, 13 Oct 2020 19:10:50 +0200 Subject: [PATCH] added move start&end --- helix-view/src/prompt.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 98389a97..3cb15f68 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -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, ..