From 22385a1dd2ed2b43ec61ba454d0b5d2317153cd6 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Sat, 10 Oct 2026 19:43:04 -0700 Subject: [PATCH] fix: retain the visible page while redirecting stale opens Reconcile a loaded section against the latest notebook catalog before parking the visible page scene or ending its recording. When a deleted section redirects to a surviving one, the current page remains drawable until that replacement actually opens. Fixes #109 Assisted-by: gpt-6.1-sol --- crates/snowbound/src/main.rs | 59 ++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/crates/snowbound/src/main.rs b/crates/snowbound/src/main.rs index 9cf8ea007e5d1bec7a421596003f0085fff95eaa..0835e09af34e797830a9441293350732d379fbe4 100644 --- a/crates/snowbound/src/main.rs +++ b/crates/snowbound/src/main.rs @@ -3847,6 +3847,35 @@ impl State { } lap("switch pictures", opening.since); let requested = opening.requested; + if let Shown::Section(session) | Shown::Created(session) = &mut opening.loaded + && let Some(library) = self + .notebooks + .iter() + .find(|listed| { + listed.location == session.library.location + && Arc::ptr_eq(&listed.structure, &session.library.structure) + && !Arc::ptr_eq(listed, &session.library) + }) + .cloned() + { + let identity = session + .library + .section_identity(&session.tabs[session.tab].path); + let path = library.catalog().and_then(|catalog| { + catalog + .sections() + .find(|section| Some(section.file_id) == identity) + .map(|section| section.path.clone()) + }); + if let Some(path) = path { + session.follow(library, &path)?; + } else if let Some(path) = library.first_section() { + return self.apply(Command::OpenSection(library, path)); + } else { + self.switching = None; + return self.adopt(library, None); + } + } // A recording goes on the page it started on. self.stop_recording(true)?; // The page shown so far keeps what was typed while the next one loaded. @@ -3869,35 +3898,7 @@ impl State { } let created = matches!(opening.loaded, Shown::Created(_)); match opening.loaded { - Shown::Section(mut session) | Shown::Created(mut session) => { - if let Some(library) = self - .notebooks - .iter() - .find(|listed| { - listed.location == session.library.location - && Arc::ptr_eq(&listed.structure, &session.library.structure) - && !Arc::ptr_eq(listed, &session.library) - }) - .cloned() - { - let identity = session - .library - .section_identity(&session.tabs[session.tab].path); - let path = library.catalog().and_then(|catalog| { - catalog - .sections() - .find(|section| Some(section.file_id) == identity) - .map(|section| section.path.clone()) - }); - if let Some(path) = path { - session.follow(library, &path)?; - } else if let Some(path) = library.first_section() { - return self.apply(Command::OpenSection(library, path)); - } else { - self.switching = None; - return self.adopt(library, None); - } - } + Shown::Section(session) | Shown::Created(session) => { // The settings keep the notebook shown, not the section. let other_notebook = self .session -- 2.54.0