diff options
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/commands.rs | 16 | ||||
-rw-r--r-- | helix-view/src/keymap.rs | 8 | ||||
-rw-r--r-- | helix-view/src/prompt.rs | 38 |
3 files changed, 38 insertions, 24 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 888317e7..6efbf98d 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -307,20 +307,8 @@ pub fn append_mode(view: &mut View, _count: usize) { }) } -pub fn prompt_mode(view: &mut View, _count: usize) { - view.state.mode = Mode::Prompt; -} - -pub fn move_char_left_prompt(prompt: &mut Prompt, _char: char) { - if prompt.cursor_loc > 1 { - prompt.cursor_loc -= 1; - } -} - -pub fn move_char_right_prompt(prompt: &mut Prompt, _char: char) { - if prompt.cursor_loc < prompt.buffer.len() { - prompt.cursor_loc += 1; - } +pub fn command_mode(view: &mut View, _count: usize) { + view.state.mode = Mode::Command; } // TODO: I, A, o and O can share a lot of the primitives. diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index d6d44779..69e6cabb 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -163,7 +163,7 @@ pub fn default() -> Keymaps { vec![key!('p')] => commands::paste, vec![key!('>')] => commands::indent, vec![key!('<')] => commands::unindent, - vec![key!(':')] => commands::prompt_mode, + vec![key!(':')] => commands::command_mode, vec![Key { code: KeyCode::Esc, modifiers: Modifiers::NONE @@ -209,11 +209,5 @@ pub fn default() -> Keymaps { vec![key!('g')] => commands::move_file_start as Command, vec![key!('e')] => commands::move_file_end as Command, ), - state::Mode::Prompt => hashmap!( - vec![Key { - code: KeyCode::Esc, - modifiers: Modifiers::NONE - }] => commands::normal_mode as Command, - ) ) } 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(), _ => (), } } |