diff --git a/rust-modules/ui/src/containers/mod.rs b/rust-modules/ui/src/containers/mod.rs index 67fce7ba2..655ba1228 100644 --- a/rust-modules/ui/src/containers/mod.rs +++ b/rust-modules/ui/src/containers/mod.rs @@ -248,10 +248,16 @@ impl Navigation { /// routing performed here cannot drift. pub fn request(&mut self, op: NavOp, ret: ReturnState) -> Vec> { if self.moves_page(&op) { - let ret = if let Some(InputOwner::Entry(owner)) = self.modals.input_owner() { - if let Some(e) = self.modals.entry_mut(owner) { e.ret = ret; } - self.top_page().map(|e| e.ret.clone()).unwrap_or_default() - } else { ret }; + // `ret` lands on the page only when it was captured there: a live surface keeps its + // own, and one captured on a surface that has closed since is dropped. + let ret = match self.modals.input_owner() { + Some(InputOwner::Entry(owner)) => { + if let Some(e) = self.modals.entry_mut(owner) { e.ret = ret; } + None + } + _ if ret.focus.is_some_and(|f| self.top_page().map(|e| e.id) != Some(f.entry)) => None, + _ => Some(ret), + }.unwrap_or_else(|| self.top_page().map(|e| e.ret.clone()).unwrap_or_default()); self.tabs.stack.request(op, ret); return Vec::new(); } diff --git a/rust-modules/ui/src/containers/tests.rs b/rust-modules/ui/src/containers/tests.rs index 21a8059af..f5bb07036 100644 --- a/rust-modules/ui/src/containers/tests.rs +++ b/rust-modules/ui/src/containers/tests.rs @@ -3187,3 +3187,24 @@ fn the_owner_after_dismissals_is_the_page_once_the_surfaces_dismiss_is_parked() assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(home))); assert_eq!(d.input_owner_after_dismissals(), d.nav.input_owner(), "after the commit the two agree"); } + +/// **A page op parked behind a menu's `Dismiss` keeps the host's return spot.** Go to Movie in the +/// item hold menu parks the menu's `Dismiss`, then the app's `Push`, both captured on the menu's +/// row. The row's key used to reach the host's `ret`, so its `Enter(Restored)` missed and the page +/// ran to its top while the menu closed, and BACK came back to the top instead of the card. +#[test] +fn a_push_parked_behind_a_surfaces_dismiss_keeps_the_hosts_return_spot() { + let (mut d, mut rig, _) = booted(); + let home = d.nav.top_page().unwrap().id; + let card = FocusKey { entry: home, elem: 3 }; + d.set_focus(Some(card)); + let menu = open_modal(&mut d, &mut rig, Style::Compact, 16); + let row = FocusKey { entry: menu, elem: 1 }; + d.set_focus(Some(row)); + assert_eq!(d.nav.entry(home).unwrap().ret.focus, Some(card), "captured at the Present"); + d.request(MachineId::Nav, NavOp::Dismiss(menu)); + d.request(MachineId::Nav, NavOp::Push(FixtureArg::Page(20))); + d.frame(&mut rig, tick(32), vec![], vec![], &mut NoTap); + assert_eq!(d.nav.entry(home).unwrap().ret.focus, Some(card), + "the closing menu's row did not replace the host's return spot"); +}