Compare commits

..
Author SHA1 Message Date
autocraft-bot[bot] a36ac6598c Merge main (e7b67fb0) into the pull request
Merge resolved. app/frame.rs, app/keys.rs and menus.rs take main's side,

Merge resolved. app/frame.rs, app/keys.rs and menus.rs take main's side, because the PR's edits there targeted code main removed. The framework already turns off egui's keyboard zoom. The engine change merged cleanly. In `SlideApp::fire` (app/commands.rs), a key-fired `view.zoomIn` now runs `format.subscript`, or `format.superscript` when Shift is held, while text or shapes are selected. Buttons, and the key with nothing selected, still zoom. The regression test stays in tests/autocraft_regression_1926.rs, rewritten to use only the crate's public API (Platform, SlideApp::new). It has the PR's two tests plus one that Ctrl+= still zooms with nothing selected. There is no cfg(test) change in lib.rs and no allow attribute. All three tests pass, and fmt and clippy on ui-egui are clean.
2026-12-02 11:35:10 +00:00
aiongg c3deb83ec5 Apply review fixes
- crates/ui-egui/src/app/frame.rs
2026-11-07 01:04:03 +00:00
aiongg 39d54845c0 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
2026-11-07 00:35:42 +00:00
3 changed files with 115 additions and 0 deletions
+2
View File
@@ -168,6 +168,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);
+10
View File
@@ -381,6 +381,16 @@ impl SlideApp {
if fired.source == FireSource::Palette {
CommandPalette::remember(&mut self.palette_recents, fired.command.clone());
}
// Ctrl+= and Ctrl+Shift+= are also Subscript and Superscript: the key formats while text or shapes are
// selected and zooms only with nothing to format. Buttons keep zooming.
let id = if id == "view.zoomIn"
&& fired.source == FireSource::Key
&& self.session.active().is_some_and(|d| d.selection.text.is_some() || !d.selection.shapes.is_empty())
{
if fired.mods.shift || ctx.input(|i| i.modifiers.shift) { "format.superscript" } else { "format.subscript" }
} else {
id
};
match id {
"edit.paste" => self.paste(ctx, fired.pasted.clone()),
"edit.copy" | "edit.cut" if fired.command.key_text().as_ref() == fired.command.id.as_str() => {
@@ -0,0 +1,103 @@
//! #1926: Ctrl+= (Subscript) and Ctrl+Shift+= (Superscript) zoomed or twitched the screen instead.
use std::sync::Arc;
use deckcraft_engine::Session;
use deckcraft_ui_egui::{Platform, Services, SlideApp};
use egui::{Key, Modifiers};
use egui_kittest::Harness;
use serde_json::json;
struct Window(SlideApp);
impl eframe::App for Window {
fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
self.0.raw_input_hook(ctx, raw);
}
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.0.logic(ctx);
}
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
self.0.ui(ui);
}
}
fn window(cc: &mut eframe::CreationContext<'_>, session: Session) -> Window {
let host = craft::host::Host::builder(craft::host::AppInfo { id: "deckcraft", name: "DeckCraft", version: "0" })
.files(Arc::new(craft::host::ScriptedFiles::new()))
.build();
let clipboard = craft::platform::clipboard::Clipboard::new(craft::platform::clipboard::MemoryClipboard::default());
let platform = Platform {
install: craft::ui::runtime::InstallSpec::new(Default::default(), Arc::new(craft::window::system::SystemWindows))
.app_id("deckcraft")
.clipboard(clipboard),
host,
settings: craft::settings::Location::Memory,
intake: None,
audio_out: None,
control: None,
frame: craft::window::policy::Frame::Native,
at_exit: None,
};
let mut app = SlideApp::new(&cc.egui_ctx, platform).unwrap_or_else(|error| panic!("window installation failed: {error}"));
app.session = session;
app.services = Services::default();
Window(app)
}
fn harness_of(session: Session) -> Harness<'static, Window> {
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_eframe(move |cc| window(cc, session));
h.run_steps(4);
h
}
fn harness() -> Harness<'static, Window> {
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!({}));
harness_of(s)
}
fn baseline_of(h: &Harness<'_, Window>) -> Option<f64> {
let st = h.state().0.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().0.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);
assert!(h.state().0.ui.zoom.is_none(), "Ctrl+= must not zoom the slide while there is text to format");
}
#[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().0.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);
assert!(h.state().0.ui.zoom.is_none(), "Ctrl+Shift+= must not zoom the slide while there is text to format");
}
#[test]
fn ctrl_equals_zooms_with_nothing_to_format() {
let mut h = harness_of(Session::with_new());
h.key_press_modifiers(Modifiers::COMMAND, Key::Equals);
h.run_steps(1);
assert!(h.state().0.ui.zoom.is_some(), "Ctrl+= zooms in when no text or shape is selected");
}