From 5aee7da0e30d59f09659356bb7c230532f3a389f Mon Sep 17 00:00:00 2001 From: clover caruso Date: Mon, 19 Oct 2026 16:33:31 -0700 Subject: [PATCH] fix: hand a section's open to the pane asking for it last A pane asking for a section another load is opening from its file now takes that load over, whichever pane started it and whether or not that pane still waits for it, so the file never opens twice and no load waits out the other's lock. A version deleted, a version restored or a page copied now finishes in the pane that asked, wherever the focus went meanwhile, and a parked pane no longer follows a section deleted into the recycle bin; it closes as it does when the section leaves the notebook. Only replays split the page area yet. Assisted-by: claude-opus-5.5 --- crates/snowbound/src/main.rs | 54 +++++++++++++++++++---------------- crates/snowbound/src/split.rs | 3 ++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/crates/snowbound/src/main.rs b/crates/snowbound/src/main.rs index f4b1e76a06fa8a1a1d6639fcc3e3ad42cbb5b1b8..9f2bb2cabf81c4a0efed2a253546f0042517d3b8 100644 --- a/crates/snowbound/src/main.rs +++ b/crates/snowbound/src/main.rs @@ -3732,21 +3732,23 @@ impl State { return Ok(()); } // A section opens from its file once: a load already opening it shows it here, - // and a parked pane that asked for it first leaves it to this one. + // and a parked pane that asked for it first, if any still waits, leaves it to + // this one. let opening = (self.opening_files.iter()) - .find(|(_, opening)| *opening == key) + .rfind(|(_, opening)| *opening == key) .map(|(request, _)| *request); - if opening == Some(self.pane.loading) { - return Ok(()); - } - let asked = - (self.parked.iter()).position(|parked| Some(parked.pane.loading) == opening); - if let Some(at) = asked { - let fresh = self.request(); - let pane = &mut self.parked[at].pane; - let (request, opened) = (pane.loading, pane.opening.take()); - (pane.loading, pane.switching) = (fresh, None); - (self.pane.loading, self.pane.opening) = (request, opened); + if let Some(request) = opening { + if request != self.pane.loading { + let fresh = self.request(); + let asked = (self.parked.iter_mut()) + .map(|parked| &mut parked.pane) + .find(|pane| pane.loading == request); + let opened = asked.and_then(|pane| { + (pane.loading, pane.switching) = (fresh, None); + pane.opening.take() + }); + (self.pane.loading, self.pane.opening) = (request, opened); + } return Ok(()); } let notify = notify(self.proxy.clone()); @@ -3983,8 +3985,8 @@ impl State { } /// Does `operation`, an edit of the open section's pages `spaces` or its list without - /// any, then shows it in every pane on the section and runs `then` if that is still the - /// open one. + /// any, then shows it in every pane on the section and runs `then` in the pane that asked, + /// wherever the focus is, while that pane still shows the section. fn section_edit< T: Send + 'static, F: Future> + Send + 'static, @@ -3994,18 +3996,22 @@ impl State { operation: F, then: impl FnOnce(&mut State, T) -> Result<(), Box> + Send + 'static, ) -> Result<(), Box> { - let key = self.session.as_ref().ok_or("No section is open")?.key(); + let (key, asker) = ( + self.session.as_ref().ok_or("No section is open")?.key(), + self.pane.id, + ); self.complete_async(operation, move |state, result| { let value = result?; state.edited_sections(&key, spaces, |shown| shown == key); - if state - .session - .as_ref() - .is_some_and(|session| session.key() == key) - { - then(state, value) - } else { - Ok(()) + // What follows is the asking pane's, while it still shows the section. + let then = move |state: &mut State| match &state.session { + Some(session) if session.key() == key => then(state, value), + _ => Ok(()), + }; + match (state.parked.iter()).position(|parked| parked.pane.id == asker) { + Some(at) => state.in_pane(at, then), + None if state.pane.id == asker => then(state), + None => Ok(()), } }) } diff --git a/crates/snowbound/src/split.rs b/crates/snowbound/src/split.rs index 42ebec0c67cec43cbdc31df2d3350872ce2fcdbf..67458d6c1baf62346847fca3fde67b2cb6178527 100644 --- a/crates/snowbound/src/split.rs +++ b/crates/snowbound/src/split.rs @@ -178,10 +178,13 @@ impl State { } let old = Some(session.key()); let identity = (session.library).section_identity(&session.tabs[session.tab].path); + // A section deleted lies in the recycle bin, where a pane doesn't follow it. + let binned = crate::recycle::binned(&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()) + .filter(|path| binned || !crate::recycle::binned(path)) }); match path.map(|path| session.follow(Arc::clone(library), &path)) { Some(Ok(())) => { -- 2.54.1