aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorJan Hrastnik2020-10-13 17:10:50 +0000
committerBlaž Hrastnik2020-10-16 03:01:21 +0000
commit3c0f187c5bd24b0af7699cf813a151088b2217d0 (patch)
treeed3f0a8a9044fefd97f35413ae595a222d202d0e /helix-view
parent7d58378374388c031ad09ceb2e27d4a0792d636e (diff)
added move start&end
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/prompt.rs32
1 files 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,
..