summaryrefslogtreecommitdiff
path: root/helix-view/src
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
parent49b4cdb5669b1c572b2b26af4353cb16cb1260f7 (diff)
Bugfix
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/commands.rs17
-rw-r--r--helix-view/src/prompt.rs35
2 files changed, 33 insertions, 19 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index 6efbf98d..33fc06e4 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -307,8 +307,19 @@ pub fn append_mode(view: &mut View, _count: usize) {
})
}
-pub fn command_mode(view: &mut View, _count: usize) {
- view.state.mode = Mode::Command;
+pub fn command_mode(_view: &mut View, _count: usize) {
+ use crate::Editor;
+
+ let prompt = Prompt::new(
+ ":".to_owned(),
+ |_input: &str| None, // completion
+ |editor: &mut Editor, input: &str| match input {
+ "q" => editor.should_close = true,
+ _ => (),
+ },
+ );
+
+ // set_prompt(prompt)
}
// TODO: I, A, o and O can share a lot of the primitives.
@@ -627,7 +638,7 @@ pub fn unindent(view: &mut View, _count: usize) {
append_changes_to_history(view);
}
-pub fn indent_selection(view: &mut View, _count: usize) {
+pub fn indent_selection(_view: &mut View, _count: usize) {
// loop over each line and recompute proper indentation
unimplemented!()
}
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),
_ => (),
}
}