on master help sign in
added move start&end
commit3c0f187c5bd24b0af7699cf813a151088b2217d0 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateTue 13 Oct 2020, 19:10 (6 years ago) parent7d58378
1 file changed+26−6
helix-view/src/prompt.rs+26−6
helix-view/src/prompt.rs+26−6
@@ -1,6 +1,6 @@
11use crate::commands;
22use crate::View;
3−use crossterm::event::{KeyCode, KeyEvent};
3+use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
44use std::string::String;
55
66pub struct Prompt {
@@ -22,18 +22,26 @@ impl Prompt {
2222 self.cursor_loc += 1;
2323 }
2424
25− pub fn move_char_left_prompt(&mut self) {
25+ pub fn move_char_left(&mut self) {
2626 if self.cursor_loc > 1 {
2727 self.cursor_loc -= 1;
2828 }
2929 }
3030
31− pub fn move_char_right_prompt(&mut self) {
31+ pub fn move_char_right(&mut self) {
3232 if self.cursor_loc < self.buffer.len() {
3333 self.cursor_loc += 1;
3434 }
3535 }
3636
37+ pub fn move_start(&mut self) {
38+ self.cursor_loc = 0;
39+ }
40+
41+ pub fn move_end(&mut self) {
42+ self.cursor_loc = self.buffer.len();
43+ }
44+
3745 pub fn delete_char_backwards(&mut self) {
3846 if self.cursor_loc > 0 {
3947 self.buffer.remove(self.cursor_loc - 1);
@@ -41,11 +49,15 @@ impl Prompt {
4149 }
4250 }
4351
52+ pub fn success_fn() {
53+ // TODO:
54+ }
55+
4456 pub fn handle_input(&mut self, key_event: KeyEvent, view: &mut View) {
4557 match key_event {
4658 KeyEvent {
4759 code: KeyCode::Char(c),
48− ..
60+ modifiers: KeyModifiers::NONE,
4961 } => self.insert_char(c),
5062 KeyEvent {
5163 code: KeyCode::Esc, ..
@@ -53,11 +65,19 @@ impl Prompt {
5365 KeyEvent {
5466 code: KeyCode::Right,
5567 ..
56− } => self.move_char_right_prompt(),
68+ } => self.move_char_right(),
5769 KeyEvent {
5870 code: KeyCode::Left,
5971 ..
60− } => self.move_char_left_prompt(),
72+ } => self.move_char_left(),
73+ KeyEvent {
74+ code: KeyCode::Char('e'),
75+ modifiers: KeyModifiers::CONTROL,
76+ } => self.move_end(),
77+ KeyEvent {
78+ code: KeyCode::Char('a'),
79+ modifiers: KeyModifiers::CONTROL,
80+ } => self.move_start(),
6181 KeyEvent {
6282 code: KeyCode::Backspace,
6383 ..