aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/prompt.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-16 07:58:26 +0000
committerBlaž Hrastnik2020-10-16 07:58:26 +0000
commitbc2c652fe885c7e7953224268688a6d7b6dea80e (patch)
tree4fc870f35222ab9e76d68c045cc16832924a6607 /helix-view/src/prompt.rs
parent49b4cdb5669b1c572b2b26af4353cb16cb1260f7 (diff)
Bugfix
Diffstat (limited to 'helix-view/src/prompt.rs')
-rw-r--r--helix-view/src/prompt.rs35
1 files changed, 19 insertions, 16 deletions
diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs
index f0ae44c9..a3feaeec 100644
--- a/helix-view/src/prompt.rs
+++ b/helix-view/src/prompt.rs
@@ -4,54 +4,57 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::string::String;
pub struct Prompt {
- pub buffer: String,
- pub cursor_loc: usize,
+ pub prompt: String,
+ pub line: String,
+ pub cursor: usize,
completion_fn: Box<dyn FnMut(&str) -> Option<Vec<&str>>>,
callback_fn: Box<dyn FnMut(&mut Editor, &str)>,
}
impl Prompt {
pub fn new(
+ prompt: String,
completion_fn: impl FnMut(&str) -> Option<Vec<&str>> + 'static,
callback_fn: impl FnMut(&mut Editor, &str) + 'static,
) -> Prompt {
Prompt {
- buffer: String::from(""),
- cursor_loc: 0,
+ prompt,
+ line: String::new(),
+ cursor: 0,
completion_fn: Box::new(completion_fn),
callback_fn: Box::new(callback_fn),
}
}
pub fn insert_char(&mut self, c: char) {
- self.buffer.insert(self.cursor_loc, c);
- self.cursor_loc += 1;
+ self.line.insert(self.cursor, c);
+ self.cursor += 1;
}
pub fn move_char_left(&mut self) {
- if self.cursor_loc > 1 {
- self.cursor_loc -= 1;
+ if self.cursor > 1 {
+ self.cursor -= 1;
}
}
pub fn move_char_right(&mut self) {
- if self.cursor_loc < self.buffer.len() {
- self.cursor_loc += 1;
+ if self.cursor < self.line.len() {
+ self.cursor += 1;
}
}
pub fn move_start(&mut self) {
- self.cursor_loc = 0;
+ self.cursor = 0;
}
pub fn move_end(&mut self) {
- self.cursor_loc = self.buffer.len();
+ self.cursor = self.line.len();
}
pub fn delete_char_backwards(&mut self) {
- if self.cursor_loc > 0 {
- self.buffer.remove(self.cursor_loc - 1);
- self.cursor_loc -= 1;
+ if self.cursor > 0 {
+ self.line.remove(self.cursor - 1);
+ self.cursor -= 1;
}
}
@@ -87,7 +90,7 @@ impl Prompt {
KeyEvent {
code: KeyCode::Enter,
..
- } => (self.callback_fn)(editor, &self.buffer),
+ } => (self.callback_fn)(editor, &self.line),
_ => (),
}
}