Finish chapter 5

This commit is contained in:
Timothy Warren 2019-09-03 14:57:52 -04:00
parent ae74513e88
commit b461804354

View File

@ -218,7 +218,7 @@ impl Editor {
'6' => PageDown, '6' => PageDown,
'7' => HomeKey, '7' => HomeKey,
'8' => EndKey, '8' => EndKey,
_ => input[1], // Escape, _ => Escape,
}; };
return Some(action); return Some(action);
@ -289,6 +289,16 @@ impl Editor {
if char.is_some() { if char.is_some() {
let char = char.unwrap(); let char = char.unwrap();
match char { match char {
Backspace => {
buffer.pop();
},
DeleteKey => {
buffer.pop();
},
Escape => {
self.set_status_message("");
return String::from("");
}
Enter => { Enter => {
if buffer.len() != 0 { if buffer.len() != 0 {
self.set_status_message(""); self.set_status_message("");
@ -810,7 +820,11 @@ impl Editor {
fn save(&mut self) -> io::Result<()> { fn save(&mut self) -> io::Result<()> {
if self.filename.len() == 0 { if self.filename.len() == 0 {
self.filename = self.prompt("Save as:"); self.filename = self.prompt("Save as (ESC to cancel):");
if self.filename.len() == 0 {
self.set_status_message("Save aborted");
return Ok(())
}
} }
let mut file = File::create(&self.filename)?; let mut file = File::create(&self.filename)?;