From 07eb3242603050c4ccc613112d7b909bda2de8f9 Mon Sep 17 00:00:00 2001 From: Tiago Pereira <1698241+tiper@users.noreply.github.com> Date: Thu, 19 Nov 2026 12:21:07 +0000 Subject: [PATCH] Item menu: Go to Movie keeps the card's focus while the menu closes Picking Go to Movie or Go to Show in an item's hold menu ran the page under the menu to its top as the menu closed, and BACK from the opened page came back to the top instead of the card. The menu parks its own Dismiss and the app then parks the Push, both captured while the menu's row held focus. The Dismiss commits first, so by the Push the closing menu no longer owns input, and Navigation::request wrote the row's key onto the host page's return state. The host's Enter(Restored) then missed and seated its top group. A page op's return state now 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, so the page keeps its own spot. Signed-off-by: Tiago Pereira <1698241+tiper@users.noreply.github.com> --- rust-modules/ui/src/containers/mod.rs | 14 ++++++++++---- rust-modules/ui/src/containers/tests.rs | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/rust-modules/ui/src/containers/mod.rs b/rust-modules/ui/src/containers/mod.rs index 67fce7ba25..655ba12288 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 21a8059afa..f5bb070361 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"); +}