diff --git a/src/editor.rs b/src/editor.rs index 35d7b5b..e245b46 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -218,7 +218,7 @@ impl Editor { '6' => PageDown, '7' => HomeKey, '8' => EndKey, - _ => input[1], // Escape, + _ => Escape, }; return Some(action); @@ -289,6 +289,16 @@ impl Editor { if char.is_some() { let char = char.unwrap(); match char { + Backspace => { + buffer.pop(); + }, + DeleteKey => { + buffer.pop(); + }, + Escape => { + self.set_status_message(""); + return String::from(""); + } Enter => { if buffer.len() != 0 { self.set_status_message(""); @@ -810,7 +820,11 @@ impl Editor { fn save(&mut self) -> io::Result<()> { 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)?;