| ... | ... | @@ -3732,21 +3732,23 @@ impl State { |
| 3732 | 3732 | return Ok(()); |
| 3733 | 3733 | } |
| 3734 | 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 | 3737 | let opening = (self.opening_files.iter()) |
| 3737 | | .find(|(_, opening)| *opening == key) |
| 3738 | .rfind(|(_, opening)| *opening == key) |
| 3738 | 3739 | .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 | } |
| 3750 | 3752 | return Ok(()); |
| 3751 | 3753 | } |
| 3752 | 3754 | let notify = notify(self.proxy.clone()); |
| ... | ... | @@ -3983,8 +3985,8 @@ impl State { |
| 3983 | 3985 | } |
| 3984 | 3986 | |
| 3985 | 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 |
| 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. |
| 3988 | 3990 | fn section_edit< |
| 3989 | 3991 | T: Send + 'static, |
| 3990 | 3992 | F: Future<Output = Result<T, notebook::Error>> + Send + 'static, |
| ... | ... | @@ -3994,18 +3996,22 @@ impl State { |
| 3994 | 3996 | operation: F, |
| 3995 | 3997 | then: impl FnOnce(&mut State, T) -> Result<(), Box<dyn Error>> + Send + 'static, |
| 3996 | 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 | 4003 | self.complete_async(operation, move |state, result| { |
| 3999 | 4004 | let value = result?; |
| 4000 | 4005 | 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(()), |
| 4009 | 4015 | } |
| 4010 | 4016 | }) |
| 4011 | 4017 | } |