Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattscamp committed Jul 27, 2016
1 parent f4eecc7 commit 95f6f4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/iota/chained_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ impl ChainedCmdBuilder {
if self.quit {
res.push(Command::exit_editor());
}
if res.is_empty() {
res.push(Command::noop());
}

return res;
}
Expand Down Expand Up @@ -155,6 +158,6 @@ impl<'a> ChainedCmdParser<'a> {
}
self.pos += 1;
}
str::from_utf8(&self.buffer[start..self.pos]).unwrap_or("")
str::from_utf8(&self.buffer[start..self.pos + 1]).unwrap_or("")
}
}
51 changes: 21 additions & 30 deletions src/iota/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,33 @@ impl<'e, T: Frontend> Editor<'e, T> {
None => return
};

let mut remove_overlay = false;
let mut command = BuilderEvent::Incomplete;

match self.view.overlay {
Overlay::None => { command = self.mode.handle_key_event(key) },
Overlay::None => {
let command = self.mode.handle_key_event(key);
if let BuilderEvent::Complete(c) = command {
self.handle_command(c);
}
},
_ => {
let event = self.view.overlay.handle_key_event(key);
match event {
OverlayEvent::Finished(response) => {
remove_overlay = true;
let commands = self.handle_overlay_response(response);
for cmd in commands {
if let BuilderEvent::Complete(c) = cmd {
self.handle_command(c);
}
}
}

_ => { command = BuilderEvent::Incomplete }
OverlayEvent::Finished(response) => { self.handle_overlay_cmd(response) },
_ => { return }
}
}
}

if remove_overlay {
self.view.overlay = Overlay::None;
self.view.clear(&mut self.frontend);
}

if let BuilderEvent::Complete(c) = command {
self.handle_command(c);
}

// Handles commands issued via overlay
fn handle_overlay_cmd(&mut self, event: Option<String>) {
let commands = self.handle_overlay_response(event);
for cmd in commands {
if let BuilderEvent::Complete(c) = cmd {
self.handle_command(c);
}
}
self.view.overlay = Overlay::None;
self.view.clear(&mut self.frontend);
}

/// Translate the response from an Overlay to a Command wrapped in a BuilderEvent
Expand All @@ -109,13 +105,8 @@ impl<'e, T: Frontend> Editor<'e, T> {
Overlay::Prompt { ref data, .. } => {
let mut builder = ChainedCmdBuilder::new();
let cmds: Vec<Command> = builder.parse(&**data);

if cmds.len() < 1 {
commands.push(BuilderEvent::Incomplete);
} else {
for cmd in cmds {
commands.push(BuilderEvent::Complete(cmd));
}
for cmd in cmds {
commands.push(BuilderEvent::Complete(cmd));
}
}

Expand Down

0 comments on commit 95f6f4e

Please sign in to comment.