diff --git a/crates/engine/src/keys.rs b/crates/engine/src/keys.rs index 0501a0299..cdfd9d6e5 100644 --- a/crates/engine/src/keys.rs +++ b/crates/engine/src/keys.rs @@ -175,6 +175,8 @@ impl Session { "end" => "End", "tab" => "Tab", "space" | " " => "Space", + // Ctrl+Shift+= reaches us as the shifted character, `+`; shortcuts are written with `=`. + "+" if mods.shift => "=", _ => k, }; let found = crate::command_specs().iter().find(|c| c.shortcut.is_some_and(|s| shortcut_matches(s, key_name, mods))).map(|c| c.id); diff --git a/crates/ui-egui/src/app/keys.rs b/crates/ui-egui/src/app/keys.rs index 7523308c0..af9817825 100644 --- a/crates/ui-egui/src/app/keys.rs +++ b/crates/ui-egui/src/app/keys.rs @@ -49,6 +49,10 @@ impl SlideApp { /// Keyboard and clipboard for the slide (when no text field has focus). pub(super) fn keyboard(&mut self, ctx: &egui::Context) { + // egui's own Ctrl+=/Ctrl+- zoom acts on the same keys as Subscript and Superscript, changing + // the zoom factor for a frame before `ui_setup` puts it back (the screen twitches). The app + // has its own zoom commands. + ctx.options_mut(|o| o.zoom_with_keyboard = false); let events = ctx.input(|i| i.events.clone()); // Ctrl+V with only an image on the clipboard: egui-winit sends no Paste event and swallows the // key press, so the release of a V press never seen is the paste. Tracked even while a text diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index fb4c50fc4..8c7c93432 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -60,6 +60,10 @@ pub fn ui_shortcut(app: &mut SlideApp, key: egui::Key, m: Mods) -> bool { } (P, true, true, false) => "app.palette", (Comma, true, false, false) => "app.preferences", + // Ctrl+= is Subscript while text or shapes are selected; it zooms only with nothing to format. + (Equals, true, false, false) if app.session.active().is_some_and(|d| d.selection.text.is_some() || !d.selection.shapes.is_empty()) => { + return false; + } (Equals | Plus, true, false, false) => "view.zoomIn", (Minus, true, false, false) => "view.zoomOut", (Num0, true, false, false) => "view.fit", diff --git a/crates/ui-egui/tests/autocraft_regression_1926.rs b/crates/ui-egui/tests/autocraft_regression_1926.rs new file mode 100644 index 000000000..118d83d5b --- /dev/null +++ b/crates/ui-egui/tests/autocraft_regression_1926.rs @@ -0,0 +1,55 @@ +//! #1926: Ctrl+= (Subscript) and Ctrl+Shift+= (Superscript) zoomed or twitched the screen instead. + +use deckcraft_engine::Session; +use deckcraft_ui_egui::{Services, SlideApp}; +use egui::{Key, Modifiers}; +use egui_kittest::Harness; +use serde_json::json; + +fn harness() -> Harness<'static, SlideApp> { + let mut s = Session::with_new(); + s.execute("shape.insert", &json!({"preset": "rect", "rect": [80.0, 80.0, 320.0, 80.0], "text": "Hello"})).unwrap(); + // A selected shape, not a caret: the shortcuts then format the text that is already there. + let _ = s.execute("text.exit", &json!({})); + let app = SlideApp::new(s, Services::default()); + let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state( + |ui, app: &mut SlideApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + app, + ); + h.run_steps(4); + h +} + +fn baseline_of(h: &Harness<'_, SlideApp>) -> Option { + let st = h.state().session.active().unwrap(); + st.selected_shapes() + .first() + .and_then(|sh| sh.text.as_ref()) + .and_then(|t| t.paragraphs.first()) + .and_then(|p| p.runs.first()) + .and_then(|r| r.props.baseline) +} + +#[test] +fn ctrl_equals_subscripts_without_zooming() { + let mut h = harness(); + h.key_press_modifiers(Modifiers::COMMAND, Key::Equals); + h.run_steps(1); + assert_eq!(baseline_of(&h), Some(-0.25), "status {:?}", h.state().status); + assert!(!h.ctx.options(|o| o.zoom_with_keyboard), "egui's own keyboard zoom must not act on Ctrl+="); + assert_eq!(h.ctx.zoom_factor(), 1.0); +} + +#[test] +fn ctrl_shift_equals_superscripts_without_zooming() { + let mut h = harness(); + // Ctrl+Shift+= is the shifted character, so egui reports it as `Plus`. + h.key_press_modifiers(Modifiers::COMMAND | Modifiers::SHIFT, Key::Plus); + h.run_steps(1); + assert_eq!(baseline_of(&h), Some(0.3), "status {:?}", h.state().status); + assert!(!h.ctx.options(|o| o.zoom_with_keyboard), "egui's own keyboard zoom must not act on Ctrl+Shift+="); + assert_eq!(h.ctx.zoom_factor(), 1.0); +}