Skip to content
Snippets Groups Projects
Commit e656ba57 authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub
Browse files

Merge pull request #80 from dummie999/master

Fix bug when entering invalid command in prompt
parents 213f051e 4b2e2c7f
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ impl Editor {
match (self.cursor().mode, cmd.key) {
(Primitive(Prompt), Char(' ')) if self.key_state.shift => {
self.prompt = String::new();
self.prompt.insert(0, String::new());
self.cursor_mut().mode = Mode::Command(CommandMode::Normal);
}
(Primitive(Insert(_)), Escape) => {
......@@ -275,20 +275,42 @@ impl Editor {
(Primitive(Insert(opt)), k) => self.insert(k, opt),
(Primitive(Prompt), Char('\n')) => {
self.cursor_mut().mode = Command(Normal);
if let Some(cmd) = PromptCommand::parse(&self.prompt.clone()) {
if let Some(cmd) = PromptCommand::parse(&self.prompt[self.prompt_index].clone()) {
self.invoke(cmd);
self.prompt = String::new();
self.redraw_task = RedrawTask::StatusBar;
} else {
self.status_bar.msg = format!("Unknown command: {}", self.prompt);
self.status_bar.msg = format!("Unknown command: {}", self.prompt[self.prompt_index]);
}
// If we use a command we used before, don't add a new line to the vec
let cmd = self.prompt[self.prompt_index].clone();
if self.prompt_index != 0 {
self.prompt[0] = cmd;
}
// Don't insert anything if the user didn't write anything
if self.prompt[self.prompt_index] != "" {
self.prompt.insert(0, String::new());
}
self.prompt_index = 0;
}
(Primitive(Prompt), Backspace) => {
self.prompt.pop();
self.prompt[self.prompt_index].pop();
self.redraw_task = RedrawTask::StatusBar;
}
(Primitive(Prompt), Up) => {
if self.prompt_index < self.prompt.len() - 1 {
self.prompt_index += 1;
}
self.redraw_task = RedrawTask::StatusBar;
}
(Primitive(Prompt), Down) => {
if self.prompt_index > 0 {
self.prompt_index -= 1;
}
self.redraw_task = RedrawTask::StatusBar;
}
(Primitive(Prompt), Char(c)) => {
self.prompt.push(c);
self.prompt[self.prompt_index].push(c);
self.redraw_task = RedrawTask::StatusBar;
}
_ => {
......
......@@ -245,7 +245,7 @@ impl Editor {
self.draw_status_bar();
for (n, c) in self.prompt.chars().enumerate() {
for (n, c) in self.prompt[self.prompt_index].chars().enumerate() {
self.window.char(
n as i32 * 8,
h as i32 - 16 - 1,
......
......@@ -168,7 +168,9 @@ pub struct Editor {
/// The status bar
pub status_bar: StatusBar,
/// The prompt
pub prompt: String,
pub prompt: Vec<String>,
/// The prompt index, usually 0
pub prompt_index: usize,
/// The settings
pub options: Options,
/// The key state
......@@ -195,7 +197,8 @@ impl Editor {
buffers: BufferManager::new(),
window: window,
status_bar: StatusBar::new(),
prompt: String::new(),
prompt: vec![String::new()],
prompt_index: 0,
options: Options::new(),
key_state: KeyState::new(),
redraw_task: RedrawTask::None,
......@@ -208,7 +211,8 @@ impl Editor {
let mut editor = Editor {
buffers: BufferManager::new(),
status_bar: StatusBar::new(),
prompt: String::new(),
prompt: vec![String::new()],
prompt_index: 0,
options: Options::new(),
key_state: KeyState::new(),
redraw_task: RedrawTask::None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment