Non-existent directory new file

This commit is contained in:
Joshua Barretto 2025-11-10 14:25:18 +00:00
parent d4e20b1063
commit 4b5579c726
4 changed files with 18 additions and 7 deletions

View file

@ -25,5 +25,4 @@
## Issues to fix ## Issues to fix
- New file creation should work with non-existent directories
- Undo history changes should not join so easily - Undo history changes should not join so easily

View file

@ -223,10 +223,11 @@ impl Buffer {
} }
pub fn save(&mut self) -> Result<(), Error> { pub fn save(&mut self) -> Result<(), Error> {
std::fs::write( let path = self.path.as_ref().expect("buffer must have path to save");
self.path.as_ref().expect("buffer must have path to save"), if let Some(parent) = path.parent() {
self.text.to_string(), std::fs::create_dir_all(parent)?;
)?; }
std::fs::write(path, self.text.to_string())?;
self.diverged = false; self.diverged = false;
self.opened_at = Some(SystemTime::now()); self.opened_at = Some(SystemTime::now());
self.unsaved = false; self.unsaved = false;

View file

@ -407,7 +407,18 @@ impl Opener {
} }
}) })
} }
Err(err) => self.options.set_options::<_, ()>(Vec::new(), |_| None), Err(err) => self.options.set_options(
if filter != "" {
vec![FileOption {
path: [dir, &file_name].into_iter().collect(),
kind: FileKind::New,
is_link: false,
}]
} else {
Vec::new()
},
|_| Some(()),
),
} }
} }
} }

View file

@ -233,7 +233,7 @@ impl Visual for SearchResult {
frame frame
.rect([0, 0], [col_a, !0]) .rect([0, 0], [col_a, !0])
.with_fg(state.theme.option_file) .with_fg(state.theme.option_file)
.text([0, 0], &format!("{name}:{}", self.loc.line_idx + 1)); .text([0, 0], &name);
// Path // Path
frame frame
.rect([col_a, 0], [col_b, !0]) .rect([col_a, 0], [col_b, !0])