FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix(ui): Space and other shortcuts keep working after dragging a pane divider (fixes #1482)
Marco Arnulfobef9a6e1274e
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 9a6393b87..398544479 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1433,6 +1433,15 @@ impl FilmcraftApp {self.menu_sent = items;}+ /// Whether keyboard focus is on a dock divider or a floating panel's resize grip, as drawn last pass.+ fn divider_focused(&self, ctx: &egui::Context) -> bool {+ let Some(focused) = ctx.memory(|m| m.focused()) else { return false };+ self.auto+ .previous+ .iter()+ .any(|e| e.response_id == Some(focused) && (e.id.starts_with("dock.gutter.") || (e.id.starts_with("panel.float.") && e.id.ends_with(".resize"))))+ }+fn handle_shortcuts(&mut self, ctx: &egui::Context) {let workspaces = (dock::names(&self.workspaces), self.ui.workspace.clone());if self.bindings_rev != self.session.shortcuts.revision || workspaces != self.menu_workspaces {@@ -1440,7 +1449,10 @@ impl FilmcraftApp {self.bindings = menus::bindings(self);self.bindings_rev = self.session.shortcuts.revision;}- if ctx.egui_wants_keyboard_input() || self.dialog == Some(Dialog::Shortcuts) {+ // A pane divider or floating-panel grip keeps focus after a pointer drag so arrows can+ // nudge it, but it takes no other key: Space and the other shortcuts keep working (#1482).+ let divider_focused = self.divider_focused(ctx);+ if (ctx.egui_wants_keyboard_input() && !divider_focused) || self.dialog == Some(Dialog::Shortcuts) {return;}// A focused text field takes every unmodified key, including the ones our shortest@@ -1498,6 +1510,10 @@ impl FilmcraftApp {if lets_text_field_keep(*m, text_focused) {continue;}+ // The focused divider consumes the arrows itself (egui matches them with any Shift/Alt).+ if divider_focused && matches!(k, egui::Key::ArrowLeft | egui::Key::ArrowRight | egui::Key::ArrowUp | egui::Key::ArrowDown) {+ continue;+ }if i.consume_key(*m, *k) {fire.push(id.clone());}diff --git a/crates/ui-egui/tests/ui_dock_resize.rs b/crates/ui-egui/tests/ui_dock_resize.rsindex 12129c957..2057ce262 100644--- a/crates/ui-egui/tests/ui_dock_resize.rs+++ b/crates/ui-egui/tests/ui_dock_resize.rs@@ -93,3 +93,47 @@ fn focused_dock_resize_owns_arrows_and_keeps_pointer_dragging() {assert_eq!(first_size(&h), 428.0);assert_eq!(h.state().session.state.playheads, before_playheads);}++fn press(h: &mut Harness<'_, FilmcraftApp>, key: Key) {+ for pressed in [true, false] {+ h.event(Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE });+ step(h);+ }+ frames(h, 2);+}++#[test]+fn space_plays_after_a_pane_is_resized_with_the_pointer() {+ let mut session = Session::default();+ session.execute("file.openDemoProject", json!({})).unwrap();+ let app = FilmcraftApp::new(session);+ let mut h = Harness::builder().with_size(vec2(1400.0, 900.0)).build_eframe(move |_| app);+ frames(&mut h, 4);+ h.state_mut().ui.focused = PanelKind::Timeline;+ h.state_mut().ui.dock = DockNode::Split {+ vertical: false,+ size: SplitSize::FixedA(400.0),+ a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project], active: 0 }),+ b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Timeline], active: 0 }),+ };+ frames(&mut h, 3);+ let element = h.state().auto.find("dock.gutter.").unwrap();+ let from = Rect::from_min_size(pos2(element.rect[0], element.rect[1]), vec2(element.rect[2], element.rect[3])).center();+ h.event(Event::PointerMoved(from));+ step(&mut h);+ h.event(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });+ step(&mut h);+ for offset in [5.0, 10.0, 15.0, 20.0] {+ h.event(Event::PointerMoved(from + vec2(offset, 0.0)));+ step(&mut h);+ }+ h.event(Event::PointerButton { pos: from + vec2(20.0, 0.0), button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });+ frames(&mut h, 3);+ assert_eq!(first_size(&h), 420.0);+ // The divider keeps keyboard focus so arrows can nudge it; that must not cost the editor its shortcuts.+ assert_eq!(h.ctx.memory(|memory| memory.focused()), Some(Id::new(("dock-gutter", String::new()))));+ press(&mut h, Key::Space);+ assert!(h.state().playback.playing, "Space must start playback after resizing a pane (#1482)");+ press(&mut h, Key::Space);+ assert!(!h.state().playback.playing);+}