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 {...@@ -3732,21 +3732,23 @@ impl State {
3732 return Ok(());3732 return Ok(());
3733 }3733 }
3734 // A section opens from its file once: a load already opening it shows it here,3734 // 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.
3736 let opening = (self.opening_files.iter())3737 let opening = (self.opening_files.iter())
3737 .find(|(_, opening)| *opening == key)3738 .rfind(|(_, opening)| *opening == key)
3738 .map(|(request, _)| *request);3739 .map(|(request, _)| *request);
3739 if opening == Some(self.pane.loading) {3740 if let Some(request) = opening {
3740 return Ok(());3741 if request != self.pane.loading {
3741 }3742 let fresh = self.request();
3742 let asked =3743 let asked = (self.parked.iter_mut())
3743 (self.parked.iter()).position(|parked| Some(parked.pane.loading) == opening);3744 .map(|parked| &mut parked.pane)
3744 if let Some(at) = asked {3745 .find(|pane| pane.loading == request);
3745 let fresh = self.request();3746 let opened = asked.and_then(|pane| {
3746 let pane = &mut self.parked[at].pane;3747 (pane.loading, pane.switching) = (fresh, None);
3747 let (request, opened) = (pane.loading, pane.opening.take());3748 pane.opening.take()
3748 (pane.loading, pane.switching) = (fresh, None);3749 });
3749 (self.pane.loading, self.pane.opening) = (request, opened);3750 (self.pane.loading, self.pane.opening) = (request, opened);
3751 }
3750 return Ok(());3752 return Ok(());
3751 }3753 }
3752 let notify = notify(self.proxy.clone());3754 let notify = notify(self.proxy.clone());
...@@ -3983,8 +3985,8 @@ impl State {...@@ -3983,8 +3985,8 @@ impl State {
3983 }3985 }
39843986
3985 /// Does `operation`, an edit of the open section's pages `spaces` or its list without3987 /// 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 the3988 /// any, then shows it in every pane on the section and runs `then` in the pane that asked,
3987 /// open one.3989 /// wherever the focus is, while that pane still shows the section.
3988 fn section_edit<3990 fn section_edit<
3989 T: Send + 'static,3991 T: Send + 'static,
3990 F: Future<Output = Result<T, notebook::Error>> + Send + 'static,3992 F: Future<Output = Result<T, notebook::Error>> + Send + 'static,
...@@ -3994,18 +3996,22 @@ impl State {...@@ -3994,18 +3996,22 @@ impl State {
3994 operation: F,3996 operation: F,
3995 then: impl FnOnce(&mut State, T) -> Result<(), Box<dyn Error>> + Send + 'static,3997 then: impl FnOnce(&mut State, T) -> Result<(), Box<dyn Error>> + Send + 'static,
3996 ) -> Result<(), Box<dyn Error>> {3998 ) -> 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 );
3998 self.complete_async(operation, move |state, result| {4003 self.complete_async(operation, move |state, result| {
3999 let value = result?;4004 let value = result?;
4000 state.edited_sections(&key, spaces, |shown| shown == key);4005 state.edited_sections(&key, spaces, |shown| shown == key);
4001 if state4006 // What follows is the asking pane's, while it still shows the section.
4002 .session4007 let then = move |state: &mut State| match &state.session {
4003 .as_ref()4008 Some(session) if session.key() == key => then(state, value),
4004 .is_some_and(|session| session.key() == key)4009 _ => Ok(()),
4005 {4010 };
4006 then(state, value)4011 match (state.parked.iter()).position(|parked| parked.pane.id == asker) {
4007 } else {4012 Some(at) => state.in_pane(at, then),
4008 Ok(())4013 None if state.pane.id == asker => then(state),
4014 None => Ok(()),
4009 }4015 }
4010 })4016 })
4011 }4017 }
crates/snowbound/src/split.rs+3
...@@ -178,10 +178,13 @@ impl State {...@@ -178,10 +178,13 @@ impl State {
178 }178 }
179 let old = Some(session.key());179 let old = Some(session.key());
180 let identity = (session.library).section_identity(&session.tabs[session.tab].path);180 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);
181 let path = library.catalog().and_then(|catalog| {183 let path = library.catalog().and_then(|catalog| {
182 (catalog.sections())184 (catalog.sections())
183 .find(|section| Some(section.file_id) == identity)185 .find(|section| Some(section.file_id) == identity)
184 .map(|section| section.path.clone())186 .map(|section| section.path.clone())
187 .filter(|path| binned || !crate::recycle::binned(path))
185 });188 });
186 match path.map(|path| session.follow(Arc::clone(library), &path)) {189 match path.map(|path| session.follow(Arc::clone(library), &path)) {
187 Some(Ok(())) => {190 Some(Ok(())) => {