only reset filename when failing to save if it was set by the user (don't convert read-only opened files to 'untitled')

This commit is contained in:
Crispy 2023-03-12 21:57:53 +01:00
parent 5035e4c295
commit 2b01ff226d
2 changed files with 6 additions and 4 deletions

View file

@ -447,8 +447,10 @@ impl Editor {
} }
fn save(&mut self) { fn save(&mut self) {
let mut filename_new = false;
if self.path.is_none() { if self.path.is_none() {
self.path = read_line("Enter path: ").map(|s| env::current_dir().unwrap().join(s)); self.path = read_line("Enter path: ").map(|s| env::current_dir().unwrap().join(s));
filename_new = true;
} }
if let Some(path) = &self.path { if let Some(path) = &self.path {
match File::create(path) { match File::create(path) {
@ -459,12 +461,14 @@ impl Editor {
} }
Err(e) => { Err(e) => {
self.message(format!("Could not save file as '{}': {e}", path.display())); self.message(format!("Could not save file as '{}': {e}", path.display()));
if filename_new {
self.path = None; self.path = None;
} }
} }
} }
} }
} }
}
fn color_selection() { fn color_selection() {
queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap(); queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap();

View file

@ -211,9 +211,7 @@ impl Navigator {
self.path = new_path; self.path = new_path;
self.selected = self.editors.len(); self.selected = self.editors.len();
} }
Err(err) => { Err(err) => self.message(format!("Could not navigate to directory: {err}")),
self.message(format!("Could not navigate to directory: {err}"));
}
} }
} }