aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/prompt.rs
diff options
context:
space:
mode:
authorJan Hrastnik2020-10-13 16:57:55 +0000
committerBlaž Hrastnik2020-10-16 03:01:21 +0000
commit7d58378374388c031ad09ceb2e27d4a0792d636e (patch)
tree087f82de0253f16458db12b4f608a8ed5d5435b9 /helix-view/src/prompt.rs
parented03ec92a825b8e42005f2f8506b0f3db4923fa5 (diff)
added move left&right, delete char
Diffstat (limited to 'helix-view/src/prompt.rs')
-rw-r--r--helix-view/src/prompt.rs38
1 files changed, 35 insertions, 3 deletions
diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs
index f1920daa..98389a97 100644
--- a/helix-view/src/prompt.rs
+++ b/helix-view/src/prompt.rs
@@ -11,17 +11,37 @@ pub struct Prompt {
impl Prompt {
pub fn new() -> Prompt {
let prompt = Prompt {
- buffer: String::from(":"), // starting prompt symbol
+ buffer: String::from(""),
cursor_loc: 0,
};
prompt
}
pub fn insert_char(&mut self, c: char) {
- self.buffer.push(c);
+ self.buffer.insert(self.cursor_loc, c);
+ self.cursor_loc += 1;
}
- pub fn handle_keyevent(&mut self, key_event: KeyEvent, view: &mut View) {
+ pub fn move_char_left_prompt(&mut self) {
+ if self.cursor_loc > 1 {
+ self.cursor_loc -= 1;
+ }
+ }
+
+ pub fn move_char_right_prompt(&mut self) {
+ if self.cursor_loc < self.buffer.len() {
+ self.cursor_loc += 1;
+ }
+ }
+
+ pub fn delete_char_backwards(&mut self) {
+ if self.cursor_loc > 0 {
+ self.buffer.remove(self.cursor_loc - 1);
+ self.cursor_loc -= 1;
+ }
+ }
+
+ pub fn handle_input(&mut self, key_event: KeyEvent, view: &mut View) {
match key_event {
KeyEvent {
code: KeyCode::Char(c),
@@ -30,6 +50,18 @@ impl Prompt {
KeyEvent {
code: KeyCode::Esc, ..
} => commands::normal_mode(view, 1),
+ KeyEvent {
+ code: KeyCode::Right,
+ ..
+ } => self.move_char_right_prompt(),
+ KeyEvent {
+ code: KeyCode::Left,
+ ..
+ } => self.move_char_left_prompt(),
+ KeyEvent {
+ code: KeyCode::Backspace,
+ ..
+ } => self.delete_char_backwards(),
_ => (),
}
}