| ... | @@ -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 | } |
| 3984 | | 3986 | |
| 3985 | /// Does `operation`, an edit of the open section's pages `spaces` or its list without | 3987 | /// 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 | 3988 | /// 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 state | 4006 | // What follows is the asking pane's, while it still shows the section. |
| 4002 | .session | 4007 | 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 | } |