Wire the keyboard focus ring's entry door — F6 → FocusPanels
Browse files at this commite4046179f952b12e8495d6c0efde888aca6f373dParent: 415844e- fix
- wire the keyboard focus ring's entry door — F6 → FocusPanels
8 changed files +105 -6
- crates/app/src/keymap.rs +21 -2
- crates/app/src/oracle.rs +4 -0
- crates/app/src/player/actions.rs +10 -0
- crates/app/src/tests/editing.rs +4 -1
- crates/app/src/tests/layout.rs +6 -0
- crates/app/src/tests/view.rs +30 -0
- crates/app/src/ui/dock_stance.rs +10 -2
- crates/app/src/ui/stance.rs +20 -1
crates/app/src/keymap.rsmodified+21 -2
| @@ -218,6 +218,12 @@ actions! { | |||
| 218 | /// this window is EDITOR." Always answerable, same as `Theme`: it is | 218 | /// this window is EDITOR." Always answerable, same as `Theme`: it is |
| 219 | /// about the editor and the project's own numbers, not about a clip. | 219 | /// about the editor and the project's own numbers, not about a clip. |
| 220 | Settings, | 220 | Settings, |
| 221 | + /// Moves the keyboard ring onto the dock (`ui::stance::Surface::Dock`, | ||
| 222 | + /// the cycle's first stop): the door into keyboard-only navigation | ||
| 223 | + /// (`ui::stance`'s Tab/Shift-Tab ring), which nothing else in the app | ||
| 224 | + /// opens. Bare Tab stays [`ActionId::Select`] at the root the whole time | ||
| 225 | + /// -- this only starts the ring, it never steals the clip-selection key. | ||
| 226 | + FocusPanels, | ||
| 221 | } | 227 | } |
| 222 | 228 | ||
| 223 | impl ActionId { | 229 | impl ActionId { |
| @@ -299,6 +305,7 @@ impl ActionId { | |||
| 299 | ActionId::Screenshot => "Save the frame on screen as a PNG", | 305 | ActionId::Screenshot => "Save the frame on screen as a PNG", |
| 300 | ActionId::SubtitleStyle => "Subtitle style: font and size…", | 306 | ActionId::SubtitleStyle => "Subtitle style: font and size…", |
| 301 | ActionId::Settings => "Settings: project and editor…", | 307 | ActionId::Settings => "Settings: project and editor…", |
| 308 | + ActionId::FocusPanels => "Move keyboard focus between panels", | ||
| 302 | } | 309 | } |
| 303 | } | 310 | } |
| 304 | 311 | ||
| @@ -378,6 +385,7 @@ impl ActionId { | |||
| 378 | ActionId::Screenshot => "screenshot", | 385 | ActionId::Screenshot => "screenshot", |
| 379 | ActionId::SubtitleStyle => "subtitle-style", | 386 | ActionId::SubtitleStyle => "subtitle-style", |
| 380 | ActionId::Settings => "settings", | 387 | ActionId::Settings => "settings", |
| 388 | + ActionId::FocusPanels => "focus-panels", | ||
| 381 | } | 389 | } |
| 382 | } | 390 | } |
| 383 | 391 | ||
| @@ -461,7 +469,11 @@ impl ActionId { | |||
| 461 | | ActionId::Fullscreen | 469 | | ActionId::Fullscreen |
| 462 | // The settings page: it changes no clip and no lane, only the | 470 | // The settings page: it changes no clip and no lane, only the |
| 463 | // project's own numbers and this window's preferences. | 471 | // project's own numbers and this window's preferences. |
| 464 | - | ActionId::Settings => Category::View, | 472 | + | ActionId::Settings |
| 473 | + // Moves the ring, not a clip or a lane: the same "how one is | ||
| 474 | + // looking/reaching, not what is being edited" shape as the rest | ||
| 475 | + // of this heading. | ||
| 476 | + | ActionId::FocusPanels => Category::View, | ||
| 465 | ActionId::Cut | 477 | ActionId::Cut |
| 466 | | ActionId::Regroup | 478 | | ActionId::Regroup |
| 467 | | ActionId::Detach | 479 | | ActionId::Detach |
| @@ -1222,6 +1234,13 @@ impl Keymap { | |||
| 1222 | // bare "," is WalkCutPrev, and nothing else answers to the | 1234 | // bare "," is WalkCutPrev, and nothing else answers to the |
| 1223 | // ctrl chord. | 1235 | // ctrl chord. |
| 1224 | b(ActionId::Settings, ",", true), | 1236 | b(ActionId::Settings, ",", true), |
| 1237 | + // The standard pane-cycle key on every desktop that has one | ||
| 1238 | + // (browsers, IDEs) -- free here, and Tab itself cannot spell | ||
| 1239 | + // this: bare Tab is already [`ActionId::Select`] at the root | ||
| 1240 | + // (a bare-key rebind would steal clip selection), and its | ||
| 1241 | + // shift pair is unspellable in this table's chord (`ctrl` | ||
| 1242 | + // only, see [`ActionId::Select`]'s own comment above). | ||
| 1243 | + b(ActionId::FocusPanels, "f6", false), | ||
| 1225 | ], | 1244 | ], |
| 1226 | } | 1245 | } |
| 1227 | } | 1246 | } |
| @@ -1500,7 +1519,7 @@ mod tests { | |||
| 1500 | #[test] | 1519 | #[test] |
| 1501 | fn every_default_stroke_reaches_its_action() { | 1520 | fn every_default_stroke_reaches_its_action() { |
| 1502 | let k = Keymap::defaults(); | 1521 | let k = Keymap::defaults(); |
| 1503 | - assert_eq!(k.entries().len(), 74); | 1522 | + assert_eq!(k.entries().len(), 75); |
| 1504 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. | 1523 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. |
| 1505 | // actually type) strides ten. | 1524 | // actually type) strides ten. |
| 1506 | assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); | 1525 | assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); |
crates/app/src/oracle.rsmodified+4 -0
| @@ -110,6 +110,10 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 110 | if action == ActionId::Theme | 110 | if action == ActionId::Theme |
| 111 | || action == ActionId::Fullscreen | 111 | || action == ActionId::Fullscreen |
| 112 | || action == ActionId::SubtitleStyle | 112 | || action == ActionId::SubtitleStyle |
| 113 | + // Moving the keyboard ring is the same kind of always-there, | ||
| 114 | + // touches-no-timeline action as the three above: there is always a | ||
| 115 | + // dock/bench/inspector to land the ring on, export or no. | ||
| 116 | + || action == ActionId::FocusPanels | ||
| 113 | { | 117 | { |
| 114 | return Enable::Yes; | 118 | return Enable::Yes; |
| 115 | } | 119 | } |
crates/app/src/player/actions.rsmodified+10 -0
| @@ -159,6 +159,16 @@ impl Player { | |||
| 159 | window.toggle_fullscreen(); | 159 | window.toggle_fullscreen(); |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | + // The ring's own door: nothing else in the app ever calls | ||
| 163 | + // `window.focus` on one of the three surface handles | ||
| 164 | + // (`ui::stance::Surface`), so without this the Tab handlers those | ||
| 165 | + // surfaces carry (`stance.rs`'s `bench`, `dock_stance.rs`'s | ||
| 166 | + // `cycle_on_key_down`) are unreachable dead code -- the ring never | ||
| 167 | + // starts. Lands on the cycle's first stop (`stance::SURFACE_CYCLE` | ||
| 168 | + // -- the dock); a second Tab from there walks it same as ever. | ||
| 169 | + ActionId::FocusPanels => { | ||
| 170 | + window.focus(&self.focus_dock); | ||
| 171 | + } | ||
| 162 | // Nothing to cancel while nothing is exporting; the export guard in | 172 | // Nothing to cancel while nothing is exporting; the export guard in |
| 163 | // the key handler is what answers this one while there is. | 173 | // the key handler is what answers this one while there is. |
| 164 | ActionId::CancelExport => {} | 174 | ActionId::CancelExport => {} |
crates/app/src/tests/editing.rsmodified+4 -1
| @@ -924,7 +924,10 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { | |||
| 924 | let allowed = action == ActionId::CancelExport | 924 | let allowed = action == ActionId::CancelExport |
| 925 | || action == ActionId::Theme | 925 | || action == ActionId::Theme |
| 926 | || action == ActionId::Fullscreen | 926 | || action == ActionId::Fullscreen |
| 927 | - || action == ActionId::SubtitleStyle; | 927 | + || action == ActionId::SubtitleStyle |
| 928 | + // Moving the ring touches no edit list either -- same kind of | ||
| 929 | + // thing as Fullscreen right above it. | ||
| 930 | + || action == ActionId::FocusPanels; | ||
| 928 | assert_eq!( | 931 | assert_eq!( |
| 929 | whole(action, busy).yes(), | 932 | whole(action, busy).yes(), |
| 930 | allowed, | 933 | allowed, |
crates/app/src/tests/layout.rsmodified+6 -0
| @@ -2633,6 +2633,12 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { | |||
| 2633 | ), | 2633 | ), |
| 2634 | (ActionId::Crossfade, "fade parity owns crossfade controls"), | 2634 | (ActionId::Crossfade, "fade parity owns crossfade controls"), |
| 2635 | (ActionId::Dissolve, "fade parity owns dissolve controls"), | 2635 | (ActionId::Dissolve, "fade parity owns dissolve controls"), |
| 2636 | + ( | ||
| 2637 | + ActionId::FocusPanels, | ||
| 2638 | + "keyboard-only by design: a mouse already focuses whatever it \ | ||
| 2639 | + clicks, so a click-through door for \"move keyboard focus\" \ | ||
| 2640 | + has nothing to do that a click has not already done", | ||
| 2641 | + ), | ||
| 2636 | ]; | 2642 | ]; |
| 2637 | let darkroom = [ | 2643 | let darkroom = [ |
| 2638 | "ui/bench_stance.rs", | 2644 | "ui/bench_stance.rs", |
crates/app/src/tests/view.rsmodified+30 -0
| @@ -933,3 +933,33 @@ fn only_tab_is_intercepted_by_a_focused_surface_everything_else_reaches_root() { | |||
| 933 | assert!(!is_focus_cycle_key(key), "{key} must bubble to the root"); | 933 | assert!(!is_focus_cycle_key(key), "{key} must bubble to the root"); |
| 934 | } | 934 | } |
| 935 | } | 935 | } |
| 936 | + | ||
| 937 | +/// The ring's other door, escape: [`ui::stance::is_focus_exit_key`] is the | ||
| 938 | +/// one branch a focused surface's `on_key_down` calls to hand focus back to | ||
| 939 | +/// the root (`Player::focus`) instead of letting escape bubble there on its | ||
| 940 | +/// own -- same pure-function-level check as the Tab gate above, since this | ||
| 941 | +/// crate has no window harness to drive a real `KeyDownEvent` through. | ||
| 942 | +#[test] | ||
| 943 | +fn escape_is_the_only_key_a_focused_surface_uses_to_leave_the_ring() { | ||
| 944 | + use crate::ui::stance::is_focus_exit_key; | ||
| 945 | + | ||
| 946 | + assert!(is_focus_exit_key("escape")); | ||
| 947 | + for key in ["tab", "space", "s", "c", "left", "right", "enter", "delete", "?"] { | ||
| 948 | + assert!(!is_focus_exit_key(key), "{key} must not exit the ring"); | ||
| 949 | + } | ||
| 950 | +} | ||
| 951 | + | ||
| 952 | +/// [`ActionId::FocusPanels`] is what starts the ring in the first place | ||
| 953 | +/// (`Player::act`'s `window.focus(&self.focus_dock)`) -- without a bound key | ||
| 954 | +/// reaching it, `next_surface`/`is_focus_cycle_key` above are unreachable | ||
| 955 | +/// dead code, exactly the defect this action closes. | ||
| 956 | +#[test] | ||
| 957 | +fn focus_panels_is_bound_and_lands_on_the_dock() { | ||
| 958 | + use keymap::{ActionId, Keymap}; | ||
| 959 | + | ||
| 960 | + let k = Keymap::defaults(); | ||
| 961 | + assert_eq!(k.lookup("f6", false), Some(ActionId::FocusPanels)); | ||
| 962 | + // Bare Tab must still mean Select at the root -- FocusPanels must not | ||
| 963 | + // have stolen it. | ||
| 964 | + assert_eq!(k.lookup("tab", false), Some(ActionId::Select)); | ||
| 965 | +} | ||
crates/app/src/ui/dock_stance.rsmodified+10 -2
| @@ -12,7 +12,7 @@ | |||
| 12 | //! [`clip_middle`]...), only the anatomy around them is new. | 12 | //! [`clip_middle`]...), only the anatomy around them is new. |
| 13 | 13 | ||
| 14 | use crate::ui::hitmap; | 14 | use crate::ui::hitmap; |
| 15 | -use crate::ui::stance::{Surface, is_focus_cycle_key, next_surface}; | 15 | +use crate::ui::stance::{Surface, is_focus_cycle_key, is_focus_exit_key, next_surface}; |
| 16 | use crate::ui::type_scale::{self, Typeset, head, label, mono}; | 16 | use crate::ui::type_scale::{self, Typeset, head, label, mono}; |
| 17 | use crate::*; | 17 | use crate::*; |
| 18 | use gpui::FontWeight; | 18 | use gpui::FontWeight; |
| @@ -1313,11 +1313,19 @@ fn cycle_on_key_down( | |||
| 1313 | surface: Surface, | 1313 | surface: Surface, |
| 1314 | ) -> impl Fn(&mut Player, &KeyDownEvent, &mut Window, &mut Context<Player>) + 'static { | 1314 | ) -> impl Fn(&mut Player, &KeyDownEvent, &mut Window, &mut Context<Player>) + 'static { |
| 1315 | move |this, event, window, cx| { | 1315 | move |this, event, window, cx| { |
| 1316 | - if is_focus_cycle_key(event.keystroke.key.as_str()) { | 1316 | + let key = event.keystroke.key.as_str(); |
| 1317 | + if is_focus_cycle_key(key) { | ||
| 1317 | let next = next_surface(surface, event.keystroke.modifiers.shift); | 1318 | let next = next_surface(surface, event.keystroke.modifiers.shift); |
| 1318 | window.focus(this.focus_handle(next)); | 1319 | window.focus(this.focus_handle(next)); |
| 1319 | cx.stop_propagation(); | 1320 | cx.stop_propagation(); |
| 1320 | cx.notify(); | 1321 | cx.notify(); |
| 1322 | + } else if is_focus_exit_key(key) { | ||
| 1323 | + // Same exit as `stance.rs`'s bench handler: leaves the ring for | ||
| 1324 | + // the root handle rather than letting escape bubble to whatever | ||
| 1325 | + // the root does with it. | ||
| 1326 | + window.focus(&this.focus); | ||
| 1327 | + cx.stop_propagation(); | ||
| 1328 | + cx.notify(); | ||
| 1321 | } | 1329 | } |
| 1322 | } | 1330 | } |
| 1323 | } | 1331 | } |
crates/app/src/ui/stance.rsmodified+20 -1
| @@ -56,6 +56,15 @@ pub(crate) fn is_focus_cycle_key(key: &str) -> bool { | |||
| 56 | key == "tab" | 56 | key == "tab" |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | +/// The other key a surface's own `on_key_down` answers: leaves the ring for | ||
| 60 | +/// the root handle (`Player::focus`) rather than letting the stroke bubble | ||
| 61 | +/// there itself -- same one-door reason as [`is_focus_cycle_key`], so the | ||
| 62 | +/// bench and both dock tabs cannot answer "what closes the ring" two | ||
| 63 | +/// different ways. | ||
| 64 | +pub(crate) fn is_focus_exit_key(key: &str) -> bool { | ||
| 65 | + key == "escape" | ||
| 66 | +} | ||
| 67 | + | ||
| 59 | impl Player { | 68 | impl Player { |
| 60 | /// The `FocusHandle` a [`Surface`] paints its ring on and Tab/Shift-Tab | 69 | /// The `FocusHandle` a [`Surface`] paints its ring on and Tab/Shift-Tab |
| 61 | /// moves to next -- one door, so `next_surface`'s answer and the handle | 70 | /// moves to next -- one door, so `next_surface`'s answer and the handle |
| @@ -596,11 +605,21 @@ fn bench( | |||
| 596 | .id("stance-bench") | 605 | .id("stance-bench") |
| 597 | .track_focus(&player.focus_bench) | 606 | .track_focus(&player.focus_bench) |
| 598 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { | 607 | .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| { |
| 599 | - if is_focus_cycle_key(event.keystroke.key.as_str()) { | 608 | + let key = event.keystroke.key.as_str(); |
| 609 | + if is_focus_cycle_key(key) { | ||
| 600 | let next = next_surface(Surface::Bench, event.keystroke.modifiers.shift); | 610 | let next = next_surface(Surface::Bench, event.keystroke.modifiers.shift); |
| 601 | window.focus(this.focus_handle(next)); | 611 | window.focus(this.focus_handle(next)); |
| 602 | cx.stop_propagation(); | 612 | cx.stop_propagation(); |
| 603 | cx.notify(); | 613 | cx.notify(); |
| 614 | + } else if is_focus_exit_key(key) { | ||
| 615 | + // Leaves the ring rather than deleting it: the root handle | ||
| 616 | + // gets focus back, and a second escape there is what does | ||
| 617 | + // whatever escape means at the root (nothing, today) -- | ||
| 618 | + // this must not itself bubble, or the root's own handler | ||
| 619 | + // never sees a stroke that stayed a ring exit. | ||
| 620 | + window.focus(&this.focus); | ||
| 621 | + cx.stop_propagation(); | ||
| 622 | + cx.notify(); | ||
| 604 | } | 623 | } |
| 605 | })) | 624 | })) |
| 606 | .flex_none() | 625 | .flex_none() |