diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 5dd2924..0341bc5 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -173,7 +173,7 @@ impl Player { // starts. Lands on the cycle's first stop (`stance::SURFACE_CYCLE` // -- the dock); a second Tab from there walks it same as ever. ActionId::FocusPanels => { - window.focus(&self.focus_dock); + self.focus_surface(crate::ui::stance::Surface::Dock, window, cx); } // Nothing to cancel while nothing is exporting; the export guard in // the key handler is what answers this one while there is. diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index b95b4e9..b08c1a3 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -912,6 +912,24 @@ fn tab_cycles_dock_bench_inspector_and_wraps() { assert_eq!(next_surface(Surface::Bench, true), Surface::Dock); } +/// The defect this closes: the dock mounts only one of its two tabs at a +/// time (`dock_stance::render`'s `match src_active`), so focusing +/// `focus_dock`/`focus_inspector` while the other tab is showing lands on a +/// handle with no tree node -- gpui then dispatches no key listener at all, +/// keyboard input is dead until a mouse click. `Player::focus_surface` +/// (`ui::stance.rs`) flips the tab first via this pure decision so the +/// surface being entered is always the one mounted. +#[test] +fn surface_wants_src_active_mounts_the_tab_before_focus_lands_on_it() { + use crate::ui::stance::{Surface, surface_wants_src_active}; + + assert_eq!(surface_wants_src_active(Surface::Dock), Some(true)); + assert_eq!(surface_wants_src_active(Surface::Inspector), Some(false)); + // Bench has no dock tab of its own -- entering it must not disturb + // whichever tab the dock was last left on. + assert_eq!(surface_wants_src_active(Surface::Bench), None); +} + /// The root fallback guarantee (main.rs:1054's "every keybind hangs off the /// root FocusHandle"): a surface's own `on_key_down` answers Tab/Shift-Tab /// and nothing else -- `cx.stop_propagation()` is only ever reached from diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 37acd3c..ba91522 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1316,9 +1316,8 @@ fn cycle_on_key_down( let key = event.keystroke.key.as_str(); if is_focus_cycle_key(key) { let next = next_surface(surface, event.keystroke.modifiers.shift); - window.focus(this.focus_handle(next)); + this.focus_surface(next, window, cx); cx.stop_propagation(); - cx.notify(); } else if is_focus_exit_key(key) { // Same exit as `stance.rs`'s bench handler: leaves the ring for // the root handle rather than letting escape bubble to whatever diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index e7c5143..97d769f 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -65,6 +65,22 @@ pub(crate) fn is_focus_exit_key(key: &str) -> bool { key == "escape" } +/// The dock mounts only one of its two tabs at a time +/// (`dock_stance::render`'s `match src_active`), so `focus_dock` only has a +/// tree node under Sources and `focus_inspector` only under Clip -- focusing +/// the unmounted one leaves gpui with a focused handle no node answers to, +/// and every key dies until the next mouse click. Answers "does entering +/// `surface` require flipping the dock tab first", pure so it's testable +/// without a `Window`: `Some(true)`/`Some(false)` is the `dock_src_active` +/// the surface needs mounted, `None` (bench) means leave the tab alone. +pub(crate) fn surface_wants_src_active(surface: Surface) -> Option { + match surface { + Surface::Dock => Some(true), + Surface::Inspector => Some(false), + Surface::Bench => None, + } +} + impl Player { /// The `FocusHandle` a [`Surface`] paints its ring on and Tab/Shift-Tab /// moves to next -- one door, so `next_surface`'s answer and the handle @@ -76,6 +92,26 @@ impl Player { Surface::Inspector => &self.focus_inspector, } } + + /// One door onto every ring move: flips the dock tab first + /// ([`surface_wants_src_active`]) so `surface`'s handle is always + /// mounted before `window.focus` lands on it, then persists the flip + /// exactly as the tab's own click does (`dock_stance::dock_tab`'s + /// `on_click`), so the ring and a mouse click can't disagree about + /// which tab was last chosen. + pub(crate) fn focus_surface( + &mut self, + surface: Surface, + window: &mut Window, + cx: &mut Context, + ) { + if let Some(src_active) = surface_wants_src_active(surface) { + self.dock_src_active = src_active; + crate::ui::dock_stance::save(src_active); + } + window.focus(self.focus_handle(surface)); + cx.notify(); + } } /// Left rail, full height (DESIGN ยง5). @@ -608,9 +644,8 @@ fn bench( let key = event.keystroke.key.as_str(); if is_focus_cycle_key(key) { let next = next_surface(Surface::Bench, event.keystroke.modifiers.shift); - window.focus(this.focus_handle(next)); + this.focus_surface(next, window, cx); cx.stop_propagation(); - cx.notify(); } else if is_focus_exit_key(key) { // Leaves the ring rather than deleting it: the root handle // gets focus back, and a second escape there is what does