From 4b5579c7269077c7098027caa9980243b3f0b257 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 10 Nov 2025 14:25:18 +0000 Subject: [PATCH] Non-existent directory new file --- README.md | 1 - src/state.rs | 9 +++++---- src/ui/prompt.rs | 13 ++++++++++++- src/ui/search.rs | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 47465b9..ebaa932 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,4 @@ ## Issues to fix -- New file creation should work with non-existent directories - Undo history changes should not join so easily \ No newline at end of file diff --git a/src/state.rs b/src/state.rs index db38dc6..408a360 100644 --- a/src/state.rs +++ b/src/state.rs @@ -223,10 +223,11 @@ impl Buffer { } pub fn save(&mut self) -> Result<(), Error> { - std::fs::write( - self.path.as_ref().expect("buffer must have path to save"), - self.text.to_string(), - )?; + let path = self.path.as_ref().expect("buffer must have path to save"); + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent)?; + } + std::fs::write(path, self.text.to_string())?; self.diverged = false; self.opened_at = Some(SystemTime::now()); self.unsaved = false; diff --git a/src/ui/prompt.rs b/src/ui/prompt.rs index 325430d..00acff1 100644 --- a/src/ui/prompt.rs +++ b/src/ui/prompt.rs @@ -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(()), + ), } } } diff --git a/src/ui/search.rs b/src/ui/search.rs index 457dcf0..b390097 100644 --- a/src/ui/search.rs +++ b/src/ui/search.rs @@ -233,7 +233,7 @@ impl Visual for SearchResult { frame .rect([0, 0], [col_a, !0]) .with_fg(state.theme.option_file) - .text([0, 0], &format!("{name}:{}", self.loc.line_idx + 1)); + .text([0, 0], &name); // Path frame .rect([col_a, 0], [col_b, !0])