diff --git a/crates/snowbound/src/manage.rs b/crates/snowbound/src/manage.rs index a73e77ac533eef1b77aa60c6a3924bf108b81695..697daf1b3db02327314d1d138948e4d8b19152a7 100644 --- a/crates/snowbound/src/manage.rs +++ b/crates/snowbound/src/manage.rs @@ -736,7 +736,7 @@ impl State { self.title(); } self.folder_rename = Some((library.location.clone(), to.clone())); - let (cache, proxy) = (self.cache.clone(), self.proxy.clone()); + let (cache, proxy, requested) = (self.cache.clone(), self.proxy.clone(), self.loading); crate::spawn_async(move || async move { let structure = Arc::clone(&library.structure); let _structure = structure.lock().await; @@ -773,7 +773,20 @@ impl State { } let reopened = Arc::new(reopened); let _ = proxy.send_event(crate::UserEvent::Then(Box::new(move |state| { - state.renamed_notebook(&library, reopened, showing.then_some(shown)); + if state + .folder_rename + .as_ref() + .is_some_and(|(from, target)| from == &library.location && target == &to) + { + state.folder_rename = None; + } + let restore = showing + && requested == state.loading + && state.notebook().is_some_and(|current| { + current.location == library.location + && Arc::ptr_eq(¤t.structure, &library.structure) + }); + state.renamed_notebook(&library, reopened, restore.then_some(shown)); if let Some(problem) = problem { platform::alert("Couldn't rename the folder", &problem); } @@ -791,7 +804,6 @@ impl State { reopened: Arc, shown: Option>, ) { - self.folder_rename = None; let (from, to) = (old.location.clone(), reopened.location.clone()); match (self.notebooks.iter_mut()).find(|open| Arc::ptr_eq(open, old)) { Some(open) => *open = Arc::clone(&reopened),