mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-02 10:38:15 -06:00
Fix [Bug Report] [DeckCraft] Shortcuts for superscript and subscript
Fixes #1926. - crates/ui-egui/src/menus.rs - crates/ui-egui/src/app/keys.rs - crates/engine/src/keys.rs - crates/engine/src/cmd/format.rs - crates/ui-egui/tests/autocraft_regression_1926.rs
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<f64> {
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user