diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 2bb1b44..9726d5f 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2967,6 +2967,49 @@ fn a_source_row_shows_its_name_before_anything_else() { assert_eq!(crate::LibraryTab::Audio.empty(), "none"); } +/// A room key pressed while the ring sits in the dock has to reach the room. +/// Two ways it did not: the dock's own handler could stop a key it does not +/// answer, and the body the dock mounts could leave the focused +/// `FocusHandle` with no element -- gpui dispatches only along the rendered +/// focus node's ancestors (`gpui-0.2.2` `window.rs:3982`, falling back to the +/// *window* root, which is not the room's div), so an orphaned handle kills +/// every key until the next click. Measured 2026-09-09: with KEYS open, a +/// second `?` and `space` reached no listener at all. +#[test] +fn every_dock_body_mounts_the_ring_it_is_standing_in_for() { + let dock = src_text("ui/dock_stance.rs"); + for (body, id) in [ + ("sources", "\"dock-sources\""), + ("clip", "\"dock-clip\""), + ("keys", "\"dock-keys-rows\""), + ] { + let after = dock + .split(id) + .nth(1) + .unwrap_or_else(|| panic!("the dock's {body} body is gone")); + let head: String = after.lines().take(4).collect(); + assert!( + head.contains(".track_focus(") && head.contains(".on_key_down("), + "the dock's {body} body mounts no focus handle: a ring left on it dies" + ); + } + // ...and the shared handler answers exactly two keys, stopping the stroke + // only there; anything else bubbles to `ui::stance::render`'s handler. + let handler = dock + .split("fn cycle_on_key_down(") + .nth(1) + .expect("the dock's shared key handler is gone"); + let body = handler.split("\n}\n").next().unwrap(); + assert_eq!( + body.matches("cx.stop_propagation()").count(), + 3, + "the dock's key handler stops a stroke outside its tab/escape branches" + ); + for branch in ["is_focus_cycle_key(key)", "is_focus_exit_key(key)"] { + assert!(body.contains(branch), "{branch} left the dock's key handler"); + } +} + /// Focus and selection rings are drawn, never inserted: a `when(focused, /// border_1())` puts a pixel of box into the flow and every row in the dock /// steps sideways the moment the surface takes focus (hunter: h-clip-tab.png diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index a95c0dc..93f24ff 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -195,14 +195,32 @@ fn dock_tab( .pb(px(6.)) .when(active, |d| d.border_t_1().border_color(rgb(INK1()))) .cursor_pointer() - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { // The keys list is body state, not a tab (user 2026-09-09: // "remove keys section from here since we also have it next to // ledger") -- picking either tab is also the way out of it, and // the pair itself (`dock_src_active`) is what the file keeps. this.keys_open = false; - this.dock_src_active = label_text == "SOURCES"; - save(this.dock_src_active); + let surface = match label_text == "SOURCES" { + true => Surface::Dock, + false => Surface::Inspector, + }; + // Same dead-handle class as `keys_tab`'s: the tab being left + // takes its `FocusHandle`'s element out of the tree with it, so a + // ring that was on that handle has to move with the tab or the + // keyboard goes silent. Only when the ring is actually in the + // dock -- a tab picked while the bench (or nothing) has focus + // does not steal it. + let in_ring = window + .focused(cx) + .is_some_and(|f| f == this.focus_dock || f == this.focus_inspector); + match in_ring { + true => this.focus_surface(surface, window, cx), + false => { + this.dock_src_active = label_text == "SOURCES"; + save(this.dock_src_active); + } + } cx.notify(); })) .tooltip(crate::ui::widgets::tip_hover(&format!("Show {}", label_text.to_lowercase()), "", None)) @@ -1441,7 +1459,20 @@ fn clip_tab( /// An action the room would refuse right now greys to `ink4`, the same ink a /// refused verb wears (DESIGN ยง8) -- never hidden: the list is the full truth /// about the keyboard, including the strokes that would answer `No` today. -fn keys_tab(player: &Player) -> impl IntoElement { +fn keys_tab(player: &Player, cx: &mut Context) -> impl IntoElement { + // The surface this body is standing in for. `keys_tab` replaces whichever + // tab was mounted, and gpui dispatches a key only along the *rendered* + // focus node's ancestors: a `FocusHandle` whose element left the tree + // falls back to the window's own root node, which the room's handler + // (`ui::stance::render`'s div) is not -- so every key dies until the next + // click. Mounting the same handle here is what keeps `?` able to close + // the list it just opened (measured 2026-09-09: second `?` and `space` + // reached no listener at all). + let surface = match player.dock_src_active { + true => Surface::Dock, + false => Surface::Inspector, + }; + let focus = player.focus_handle(surface).clone(); let row_label = label(type_scale::CHORD_METADATA_MIN_PX, FontWeight::MEDIUM); let row_chord = mono(type_scale::CHORD_METADATA_MIN_PX, FontWeight::MEDIUM); let pair = move |text: String, chord: String, ink: u32| { @@ -1477,6 +1508,10 @@ fn keys_tab(player: &Player) -> impl IntoElement { }; div() .id("dock-keys-rows") + .track_focus(&focus) + .on_key_down(cx.listener(move |this, event: &KeyDownEvent, window, cx| { + cycle_on_key_down(surface)(this, event, window, cx) + })) .flex_1() .min_h(px(0.)) .flex() @@ -1551,7 +1586,7 @@ pub(crate) fn render( .child(dock_tab("dock-tab-clip", "CLIP", !src_active && !keys, cx)), ) .child(match (keys, src_active) { - (true, _) => keys_tab(player).into_any_element(), + (true, _) => keys_tab(player, cx).into_any_element(), (false, true) => sources_tab(player, window, cx).into_any_element(), (false, false) => clip_tab(player, width, window_size, window, cx).into_any_element(), }) diff --git a/crates/app/src/ui/theme.rs b/crates/app/src/ui/theme.rs index 284a99a..ff414f4 100644 --- a/crates/app/src/ui/theme.rs +++ b/crates/app/src/ui/theme.rs @@ -104,7 +104,6 @@ palette! { SCRIM: u32, SCRIM_LIGHT: u32, STROKE_DIVIDER: u32, - STROKE_FOCUS: u32, STROKE_SELECTED: u32, FG_PRIMARY: u32, FG_SECONDARY: u32, @@ -348,7 +347,6 @@ pub mod cool { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x2a3442; - pub const STROKE_FOCUS: u32 = 0xffd166; pub const STROKE_SELECTED: u32 = 0x22d3ee; // -- text ------------------------------------------------------------------- @@ -440,7 +438,6 @@ pub mod warm { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x3a322e; - pub const STROKE_FOCUS: u32 = 0xffc38a; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -525,7 +522,6 @@ pub mod forest { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x25362c; - pub const STROKE_FOCUS: u32 = 0xffd166; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -609,7 +605,6 @@ pub mod violet { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x2e3150; - pub const STROKE_FOCUS: u32 = 0xfde68a; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -688,7 +683,6 @@ pub mod rose { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x332f33; - pub const STROKE_FOCUS: u32 = 0xfcd34d; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -769,7 +763,6 @@ pub mod amber { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x35352f; - pub const STROKE_FOCUS: u32 = 0x7dd3fc; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -848,7 +841,6 @@ pub mod ocean { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x1e2d42; - pub const STROKE_FOCUS: u32 = 0xffd166; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -928,7 +920,6 @@ pub mod ice { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x223140; - pub const STROKE_FOCUS: u32 = 0xfcd34d; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -1006,7 +997,6 @@ pub mod orchid { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x33203f; - pub const STROKE_FOCUS: u32 = 0x7dd3fc; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -1093,7 +1083,6 @@ pub mod nord { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x434c5e; - pub const STROKE_FOCUS: u32 = 0xd08770; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -1183,7 +1172,6 @@ pub mod gruvbox { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x504945; - pub const STROKE_FOCUS: u32 = 0x83a598; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -1264,7 +1252,6 @@ pub mod dracula { // -- strokes ---------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x44475a; - pub const STROKE_FOCUS: u32 = 0x8be9fd; pub const STROKE_SELECTED: u32 = ACCENT_PRIMARY; // -- text ------------------------------------------------------------------- @@ -1360,7 +1347,6 @@ pub mod darkroom { // -- strokes -------------------------------------------------------------- pub const STROKE_DIVIDER: u32 = 0x22262b; - pub const STROKE_FOCUS: u32 = INK1; /// "Focus/selection ring = 1px ink1 (lamp-adjacent, not coloured)." pub const STROKE_SELECTED: u32 = INK1;