diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 91c1cc4..3462794 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -218,6 +218,12 @@ actions! { /// this window is EDITOR." Always answerable, same as `Theme`: it is /// about the editor and the project's own numbers, not about a clip. Settings, + /// Moves the keyboard ring onto the dock (`ui::stance::Surface::Dock`, + /// the cycle's first stop): the door into keyboard-only navigation + /// (`ui::stance`'s Tab/Shift-Tab ring), which nothing else in the app + /// opens. Bare Tab stays [`ActionId::Select`] at the root the whole time + /// -- this only starts the ring, it never steals the clip-selection key. + FocusPanels, } impl ActionId { @@ -299,6 +305,7 @@ impl ActionId { ActionId::Screenshot => "Save the frame on screen as a PNG", ActionId::SubtitleStyle => "Subtitle style: font and size…", ActionId::Settings => "Settings: project and editor…", + ActionId::FocusPanels => "Move keyboard focus between panels", } } @@ -378,6 +385,7 @@ impl ActionId { ActionId::Screenshot => "screenshot", ActionId::SubtitleStyle => "subtitle-style", ActionId::Settings => "settings", + ActionId::FocusPanels => "focus-panels", } } @@ -461,7 +469,11 @@ impl ActionId { | ActionId::Fullscreen // The settings page: it changes no clip and no lane, only the // project's own numbers and this window's preferences. - | ActionId::Settings => Category::View, + | ActionId::Settings + // Moves the ring, not a clip or a lane: the same "how one is + // looking/reaching, not what is being edited" shape as the rest + // of this heading. + | ActionId::FocusPanels => Category::View, ActionId::Cut | ActionId::Regroup | ActionId::Detach @@ -1222,6 +1234,13 @@ impl Keymap { // bare "," is WalkCutPrev, and nothing else answers to the // ctrl chord. b(ActionId::Settings, ",", true), + // The standard pane-cycle key on every desktop that has one + // (browsers, IDEs) -- free here, and Tab itself cannot spell + // this: bare Tab is already [`ActionId::Select`] at the root + // (a bare-key rebind would steal clip selection), and its + // shift pair is unspellable in this table's chord (`ctrl` + // only, see [`ActionId::Select`]'s own comment above). + b(ActionId::FocusPanels, "f6", false), ], } } @@ -1500,7 +1519,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 74); + assert_eq!(k.entries().len(), 75); // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. // actually type) strides ten. assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 2f69371..127573d 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -110,6 +110,10 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { if action == ActionId::Theme || action == ActionId::Fullscreen || action == ActionId::SubtitleStyle + // Moving the keyboard ring is the same kind of always-there, + // touches-no-timeline action as the three above: there is always a + // dock/bench/inspector to land the ring on, export or no. + || action == ActionId::FocusPanels { return Enable::Yes; } diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index cc02bb9..3915821 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -159,6 +159,16 @@ impl Player { window.toggle_fullscreen(); } } + // The ring's own door: nothing else in the app ever calls + // `window.focus` on one of the three surface handles + // (`ui::stance::Surface`), so without this the Tab handlers those + // surfaces carry (`stance.rs`'s `bench`, `dock_stance.rs`'s + // `cycle_on_key_down`) are unreachable dead code -- the ring never + // 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); + } // Nothing to cancel while nothing is exporting; the export guard in // the key handler is what answers this one while there is. ActionId::CancelExport => {} diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index b8a8763..1cc1631 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -924,7 +924,10 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { let allowed = action == ActionId::CancelExport || action == ActionId::Theme || action == ActionId::Fullscreen - || action == ActionId::SubtitleStyle; + || action == ActionId::SubtitleStyle + // Moving the ring touches no edit list either -- same kind of + // thing as Fullscreen right above it. + || action == ActionId::FocusPanels; assert_eq!( whole(action, busy).yes(), allowed, diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 9e9ad3f..f855e36 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -2633,6 +2633,12 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { ), (ActionId::Crossfade, "fade parity owns crossfade controls"), (ActionId::Dissolve, "fade parity owns dissolve controls"), + ( + ActionId::FocusPanels, + "keyboard-only by design: a mouse already focuses whatever it \ + clicks, so a click-through door for \"move keyboard focus\" \ + has nothing to do that a click has not already done", + ), ]; let darkroom = [ "ui/bench_stance.rs", diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index 13d1826..b95b4e9 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -933,3 +933,33 @@ fn only_tab_is_intercepted_by_a_focused_surface_everything_else_reaches_root() { assert!(!is_focus_cycle_key(key), "{key} must bubble to the root"); } } + +/// The ring's other door, escape: [`ui::stance::is_focus_exit_key`] is the +/// one branch a focused surface's `on_key_down` calls to hand focus back to +/// the root (`Player::focus`) instead of letting escape bubble there on its +/// own -- same pure-function-level check as the Tab gate above, since this +/// crate has no window harness to drive a real `KeyDownEvent` through. +#[test] +fn escape_is_the_only_key_a_focused_surface_uses_to_leave_the_ring() { + use crate::ui::stance::is_focus_exit_key; + + assert!(is_focus_exit_key("escape")); + for key in ["tab", "space", "s", "c", "left", "right", "enter", "delete", "?"] { + assert!(!is_focus_exit_key(key), "{key} must not exit the ring"); + } +} + +/// [`ActionId::FocusPanels`] is what starts the ring in the first place +/// (`Player::act`'s `window.focus(&self.focus_dock)`) -- without a bound key +/// reaching it, `next_surface`/`is_focus_cycle_key` above are unreachable +/// dead code, exactly the defect this action closes. +#[test] +fn focus_panels_is_bound_and_lands_on_the_dock() { + use keymap::{ActionId, Keymap}; + + let k = Keymap::defaults(); + assert_eq!(k.lookup("f6", false), Some(ActionId::FocusPanels)); + // Bare Tab must still mean Select at the root -- FocusPanels must not + // have stolen it. + assert_eq!(k.lookup("tab", false), Some(ActionId::Select)); +} diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 1537494..37acd3c 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -12,7 +12,7 @@ //! [`clip_middle`]...), only the anatomy around them is new. use crate::ui::hitmap; -use crate::ui::stance::{Surface, is_focus_cycle_key, next_surface}; +use crate::ui::stance::{Surface, is_focus_cycle_key, is_focus_exit_key, next_surface}; use crate::ui::type_scale::{self, Typeset, head, label, mono}; use crate::*; use gpui::FontWeight; @@ -1313,11 +1313,19 @@ fn cycle_on_key_down( surface: Surface, ) -> impl Fn(&mut Player, &KeyDownEvent, &mut Window, &mut Context) + 'static { move |this, event, window, cx| { - if is_focus_cycle_key(event.keystroke.key.as_str()) { + 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)); 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 + // the root does with it. + window.focus(&this.focus); + cx.stop_propagation(); + cx.notify(); } } } diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index 40afdd6..e7c5143 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -56,6 +56,15 @@ pub(crate) fn is_focus_cycle_key(key: &str) -> bool { key == "tab" } +/// The other key a surface's own `on_key_down` answers: leaves the ring for +/// the root handle (`Player::focus`) rather than letting the stroke bubble +/// there itself -- same one-door reason as [`is_focus_cycle_key`], so the +/// bench and both dock tabs cannot answer "what closes the ring" two +/// different ways. +pub(crate) fn is_focus_exit_key(key: &str) -> bool { + key == "escape" +} + 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 @@ -596,11 +605,21 @@ fn bench( .id("stance-bench") .track_focus(&player.focus_bench) .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { - if is_focus_cycle_key(event.keystroke.key.as_str()) { + 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)); 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 + // whatever escape means at the root (nothing, today) -- + // this must not itself bubble, or the root's own handler + // never sees a stroke that stayed a ring exit. + window.focus(&this.focus); + cx.stop_propagation(); + cx.notify(); } })) .flex_none()