authoravatarclover caruso<git@paperclover.net>2026-10-19 16:33:31-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 18:07:46-07:00
log5aee7da0e30d59f09659356bb7c230532f3a389f
treec24cca6dee87a985fe6f5656bea193f75d996622
parentd2b738a4ff1796471a1f7581f203e652392fc309
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

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

2 files changed, 33 insertions(+), 24 deletions(-)

crates/snowbound/src/main.rs+30-24
......@@ -3732,21 +3732,23 @@ impl State {
37323732 return Ok(());
37333733 }
37343734 // A section opens from its file once: a load already opening it shows it here,
3735 // and a parked pane that asked for it first leaves it to this one.
3735 // and a parked pane that asked for it first, if any still waits, leaves it to
3736 // this one.
37363737 let opening = (self.opening_files.iter())
3737 .find(|(_, opening)| *opening == key)
3738 .rfind(|(_, opening)| *opening == key)
37383739 .map(|(request, _)| *request);
3739 if opening == Some(self.pane.loading) {
3740 return Ok(());
3741 }
3742 let asked =
3743 (self.parked.iter()).position(|parked| Some(parked.pane.loading) == opening);
3744 if let Some(at) = asked {
3745 let fresh = self.request();
3746 let pane = &mut self.parked[at].pane;
3747 let (request, opened) = (pane.loading, pane.opening.take());
3748 (pane.loading, pane.switching) = (fresh, None);
3749 (self.pane.loading, self.pane.opening) = (request, opened);
3740 if let Some(request) = opening {
3741 if request != self.pane.loading {
3742 let fresh = self.request();
3743 let asked = (self.parked.iter_mut())
3744 .map(|parked| &mut parked.pane)
3745 .find(|pane| pane.loading == request);
3746 let opened = asked.and_then(|pane| {
3747 (pane.loading, pane.switching) = (fresh, None);
3748 pane.opening.take()
3749 });
3750 (self.pane.loading, self.pane.opening) = (request, opened);
3751 }
37503752 return Ok(());
37513753 }
37523754 let notify = notify(self.proxy.clone());
......@@ -3983,8 +3985,8 @@ impl State {
39833985 }
39843986
39853987 /// Does `operation`, an edit of the open section's pages `spaces` or its list without
3986 /// any, then shows it in every pane on the section and runs `then` if that is still the
3987 /// open one.
3988 /// any, then shows it in every pane on the section and runs `then` in the pane that asked,
3989 /// wherever the focus is, while that pane still shows the section.
39883990 fn section_edit<
39893991 T: Send + 'static,
39903992 F: Future<Output = Result<T, notebook::Error>> + Send + 'static,
......@@ -3994,18 +3996,22 @@ impl State {
39943996 operation: F,
39953997 then: impl FnOnce(&mut State, T) -> Result<(), Box<dyn Error>> + Send + 'static,
39963998 ) -> Result<(), Box<dyn Error>> {
3997 let key = self.session.as_ref().ok_or("No section is open")?.key();
3999 let (key, asker) = (
4000 self.session.as_ref().ok_or("No section is open")?.key(),
4001 self.pane.id,
4002 );
39984003 self.complete_async(operation, move |state, result| {
39994004 let value = result?;
40004005 state.edited_sections(&key, spaces, |shown| shown == key);
4001 if state
4002 .session
4003 .as_ref()
4004 .is_some_and(|session| session.key() == key)
4005 {
4006 then(state, value)
4007 } else {
4008 Ok(())
4006 // What follows is the asking pane's, while it still shows the section.
4007 let then = move |state: &mut State| match &state.session {
4008 Some(session) if session.key() == key => then(state, value),
4009 _ => Ok(()),
4010 };
4011 match (state.parked.iter()).position(|parked| parked.pane.id == asker) {
4012 Some(at) => state.in_pane(at, then),
4013 None if state.pane.id == asker => then(state),
4014 None => Ok(()),
40094015 }
40104016 })
40114017 }
crates/snowbound/src/split.rs+3
......@@ -178,10 +178,13 @@ impl State {
178178 }
179179 let old = Some(session.key());
180180 let identity = (session.library).section_identity(&session.tabs[session.tab].path);
181 // A section deleted lies in the recycle bin, where a pane doesn't follow it.
182 let binned = crate::recycle::binned(&session.tabs[session.tab].path);
181183 let path = library.catalog().and_then(|catalog| {
182184 (catalog.sections())
183185 .find(|section| Some(section.file_id) == identity)
184186 .map(|section| section.path.clone())
187 .filter(|path| binned || !crate::recycle::binned(path))
185188 });
186189 match path.map(|path| session.follow(Arc::clone(library), &path)) {
187190 Some(Ok(())) => {