|
|
|
@@ -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");
|
|
|
|
|
}
|