Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge canvas-context-menu: a context menu on the canvas for objects, text and the page

aiongg1553acb6be0a
diff --cc crates/ui-egui/src/canvas.rs
index 3010d87eb,6e7e052c4..7a584acde
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@@ -1432,7 -1337,87 +1433,87 @@@ fn ruler_units_menu(app: &mut DesignApp
}
}
+ /// A canvas context menu asked for by a right-click; `open` until the popup has opened.
+ #[derive(Clone, Copy, Debug)]
+ struct MenuRequest {
+ kind: crate::menus::ContextMenu,
+ open: bool,
+ }
+
+ /// The popup id of the canvas context menu in split-view pane `pane`.
+ fn context_menu_id(pane: u8) -> egui::Id {
+ egui::Id::new(("canvas_context_menu", pane))
+ }
+
+ /// Is a canvas context menu open (in either pane)?
+ pub fn context_menu_open(ctx: &egui::Context) -> bool {
+ (0..2).any(|pane| egui::Popup::is_id_open(ctx, context_menu_id(pane)))
+ }
+
+ /// Shows the context menu a right-click asked for. It opens a frame after the click: a click
+ /// while the menu is open closes it in that frame, and the menu then reopens where the new click was.
+ fn context_menu(app: &mut DesignApp, ui: &egui::Ui, resp: &egui::Response) {
+ let id = context_menu_id(app.pane);
+ let Some(req) = ui.data(|d| d.get_temp::<MenuRequest>(id)) else { return };
+ let open = if req.open {
+ ui.data_mut(|d| d.insert_temp(id, MenuRequest { open: false, ..req }));
+ Some(egui::SetOpenCommand::Bool(true))
+ } else {
+ None
+ };
+ egui::Popup::menu(resp)
+ .id(id)
+ .open_memory(open)
+ .at_pointer_fixed()
+ .close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)
+ .show(|ui| crate::menus::context_menu(app, ui, req.kind));
+ }
+
+ /// Prepares a right-click at canvas point `p`: picks the menu and the selection it acts on.
+ /// - Typing: a click in a text frame places the caret there as a left click would, except
+ /// inside the selected text, which stays selected; elsewhere the text is left as it is.
+ /// - On an object: it is selected first unless it already is, as the Selection tool would.
+ /// - On nothing: the selection stays.
+ fn context_target(app: &mut DesignApp, p: Point, zoom: f64) -> crate::menus::ContextMenu {
+ use crate::menus::ContextMenu;
+ let hit = item_at(app, p, zoom);
+ if app.session.wants_text() {
+ let text_frame = hit.filter(|(id, _)| app.session.active().and_then(|st| st.doc.item(*id)).is_some_and(Item::is_text_frame));
+ if let Some((id, sp)) = text_frame {
+ // A press in the selected text keeps it for dragging; end that press without a move.
+ if app.run("text.placeCaret", json!({"frame": id.0, "point": [sp.x, sp.y]})).is_ok_and(|r| r["dragging"] == json!(true)) {
+ let _ = app.run("text.release", json!({"frame": id.0, "point": [sp.x, sp.y], "moved": true}));
+ }
+ }
+ return ContextMenu::Text;
+ }
+ let Some((id, _)) = hit else { return ContextMenu::Canvas };
+ let direct = app.session.tool_id() == "directSelection";
+ let Some((target, selected)) = app.session.active().map(|st| {
+ let target = if direct { id } else { st.doc.top_level_of(id).unwrap_or(id) };
+ (target, st.selection.contains(target))
+ }) else {
+ return ContextMenu::Canvas;
+ };
+ if !selected {
+ let _ = app.run("selection.set", json!({"ids": [target.0], "content": direct}));
+ }
+ ContextMenu::Object
+ }
+
+ /// The frontmost item under canvas point `p` and that point in its spread, hit as the tools do.
+ fn item_at(app: &DesignApp, p: Point, zoom: f64) -> Option<(designcraft_doc::ItemId, Point)> {
+ let st = app.session.active()?;
+ let (sr, sp) = CanvasLayout::new(&st.doc, st.editing_parents).spread_at(p)?;
+ let tol = 4.0 / zoom.max(1e-6);
+ let id = match sr {
+ SpreadRef::Doc(si) => st.doc.hit_item(si, sp, tol)?,
+ _ => st.doc.spread(sr)?.items.iter().rev().find(|it| !it.locked && designcraft_doc::edit_hit(it, sp, tol))?.id,
+ };
+ Some((id, sp))
+ }
+
-fn fmt_tick(v: f64) -> String {
+pub(crate) fn fmt_tick(v: f64) -> String {
let r = v.round();
if (v - r).abs() < 1e-6 { format!("{}", r as i64) } else { format!("{v:.1}") }
}
@@@ -1469,11 -1456,8 +1552,11 @@@ fn handle_input(app: &mut DesignApp, ui
}
return;
}
- // Ruler guides need the rulers (hidden while the view is rotated).
+ // The zero point and ruler guides need the rulers (hidden while the view is rotated).
- if !space && xf.rot == 0 && zero_point_drag(app, ui, resp, rect, &xf) {
++ if !space && !menu_open && xf.rot == 0 && zero_point_drag(app, ui, resp, rect, &xf) {
+ return;
+ }
- if !space && xf.rot == 0 && guide_drag(app, ui, resp, rect, &xf) {
+ if !space && !menu_open && xf.rot == 0 && guide_drag(app, ui, resp, rect, &xf) {
return;
}
let m = ui.input(|i| mods(i, space));
@@@ -1482,21 -1466,22 +1565,23 @@@
let mut events: Vec<PointerEvent> = Vec::new();
let down_id = egui::Id::new(("canvas_pointer_down", app.pane));
let mut down: bool = ui.data(|d| d.get_temp(down_id)).unwrap_or(false);
- let (pressed, released, origin, latest, dbl) = ui.input(|i| {
- (
- i.pointer.primary_pressed(),
- i.pointer.primary_released(),
- i.pointer.press_origin(),
- i.pointer.latest_pos(),
- i.pointer.button_double_clicked(egui::PointerButton::Primary),
- )
- });
+ let clicks_id = egui::Id::new(("canvas_clicks", app.pane));
+ let (pressed, released, origin, latest, now) =
+ ui.input(|i| (i.pointer.primary_pressed(), i.pointer.primary_released(), i.pointer.press_origin(), i.pointer.latest_pos(), i.time));
+ let in_view = |o: Pos2| if xf.rot == 0 { rect.contains(o) } else { resp.rect.contains(o) };
if pressed
&& !space
- && let Some(o) = origin.filter(|o| (if xf.rot == 0 { rect.contains(*o) } else { resp.rect.contains(*o) }) && resp.hovered())
+ && !menu_open
+ && let Some(o) = origin.filter(|o| in_view(*o) && resp.hovered())
{
- events.push(PointerEvent { kind: if dbl { PointerKind::DoubleClick } else { PointerKind::Down }, pos: pos(o), mods: m });
+ // Count presses in a row here: egui reports double and triple clicks only on release and
+ // stops at three, but a press must know (word, line, paragraph, story).
+ // Like egui, the next press must come within the double-click delay of the last release.
+ let (delay, dist) = ui.ctx().options(|o| (o.input_options.max_double_click_delay, o.input_options.max_click_dist));
+ let (released_at, last_pos, last_n): (f64, Pos2, u8) = ui.data(|d| d.get_temp(clicks_id)).unwrap_or((f64::NEG_INFINITY, o, 0));
+ let n = if now - released_at <= delay && (o - last_pos).length() <= dist { last_n.saturating_add(1) } else { 1 };
+ ui.data_mut(|d| d.insert_temp(clicks_id, (f64::NEG_INFINITY, o, n)));
+ events.push(PointerEvent { kind: PointerKind::Down, pos: pos(o), mods: m, clicks: n });
down = true;
}
if down
@@@ -1547,23 -1540,15 +1643,23 @@@
resp.request_focus();
}
// Keyboard for the active tool.
- if (ui.ctx().text_edit_focused() && !resp.has_focus()) || !keyboard_pane(app) {
- if menu_open || (ui.ctx().text_edit_focused() && !resp.has_focus()) {
++ if menu_open || (ui.ctx().text_edit_focused() && !resp.has_focus()) || !keyboard_pane(app) {
return;
}
+ // Keys of a frame that began composing are the IME's too (a Backspace that empties the marked
+ // text must not delete the character before it).
+ let composing_at_start = app.session.tool_composing();
let evs = ui.input(|i| i.events.clone());
for e in evs {
+ let composing = composing_at_start || app.session.tool_composing();
match e {
- egui::Event::Text(t) if wants_text => {
+ egui::Event::Ime(ime) if wants_text => ime_event(app, ime, vi),
+ // Keys the IME passes through come as text only while nothing is marked.
+ egui::Event::Text(t) if wants_text && !composing => {
let _ = app.run("text.insert", json!({"text": t}));
}
+ // The IME owns the keyboard until it commits: no typing, clipboard or editing keys.
+ egui::Event::Text(_) | egui::Event::Paste(_) | egui::Event::Copy | egui::Event::Cut | egui::Event::Key { .. } if composing => {}
egui::Event::Paste(t) if wants_text => {
// Formatted when the system clipboard still holds what was copied here;
// Shift (⇧⌘V) pastes without formatting.
@@@ -2091,170 -1894,117 +2187,281 @@@ mod tests
}
}
+ /// A harness whose frames are 1 ms apart, so two clicks make a double-click.
+ fn fast_harness(app: DesignApp) -> Harness<'static, DesignApp> {
+ let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_step_dt(0.001).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ let ctx = ui.ctx().clone();
+ app.logic(&ctx);
+ app.ui(ui);
+ },
+ app,
+ );
+ h.run_steps(4);
+ h
+ }
+
+ fn primary(h: &mut Harness<'_, DesignApp>, pos: Pos2, pressed: bool) {
+ h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() });
+ h.run_steps(2);
+ }
+
+ fn corner_drag(h: &mut Harness<'_, DesignApp>, from: Pos2, to: Pos2) {
+ h.hover_at(from);
+ h.step();
+ primary(h, from, true);
+ h.event(egui::Event::PointerMoved(from + (to - from) / 2.0));
+ h.run_steps(2);
+ h.event(egui::Event::PointerMoved(to));
+ h.run_steps(2);
+ primary(h, to, false);
+ }
+
+ fn corner_click(h: &mut Harness<'_, DesignApp>, p: Pos2) {
+ h.hover_at(p);
+ h.step();
+ primary(h, p, true);
+ primary(h, p, false);
+ }
+
+ /// Where the rulers measure from (canvas coordinates): the document's zero point on the
+ /// spread in view (its first page, for a page origin).
+ fn ruler_zero(app: &DesignApp, doc: &Document, layout: &CanvasLayout) -> Option<Point> {
+ ruler_pieces(app, doc, layout, doc.zero_point()).first().map(|p| p.2)
+ }
+
+ fn zero_point(h: &Harness<'_, DesignApp>) -> [f64; 2] {
+ h.state().session.doc().unwrap().doc.settings.zero_point
+ }
+
+ #[test]
+ fn the_ruler_corner_drags_resets_and_locks_the_zero_point() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"pages": 3})).unwrap();
+ let mut h = fast_harness(app);
+ let rect = h.state().canvas_rect.unwrap();
+ let corner = rect.min - vec2(RULER / 2.0, RULER / 2.0);
+ // A click that stays in the corner leaves the zero point.
+ corner_click(&mut h, corner);
+ assert_eq!(zero_point(&h), [0.0, 0.0]);
+ // Dragged out, it lands where released, measured from the spread in view.
+ let dest = rect.min + vec2(80.0, 50.0);
+ let expected = {
+ let app = h.state();
+ let st = app.session.active().unwrap();
+ let layout = CanvasLayout::new(&st.doc, false);
+ let slot = layout.slots[current_slot(app, &layout).unwrap()];
+ let sp = slot.to_spread(Xf::new(rect, app.view().unwrap()).to_canvas(dest));
+ let b = st.doc.spread(slot.spread).unwrap().bounds();
+ [sp.x - b.x0, sp.y - b.y0]
+ };
+ corner_drag(&mut h, corner, dest);
+ let zp = zero_point(&h);
+ assert!((zp[0] - expected[0]).abs() < 0.5 && (zp[1] - expected[1]).abs() < 0.5, "{zp:?} vs {expected:?}");
+ assert!(zp[0].abs() > 1.0 && zp[1].abs() > 1.0, "moved: {zp:?}");
+ // The rulers measure from the point it was dropped on.
+ {
+ let app = h.state();
+ let st = app.session.active().unwrap();
+ let layout = CanvasLayout::new(&st.doc, false);
+ let o = ruler_zero(app, &st.doc, &layout).unwrap();
+ let on_screen = Xf::new(rect, app.view().unwrap()).to_screen(o);
+ assert!((on_screen - dest).length() < 0.5, "{on_screen:?} vs {dest:?}");
+ }
+ // A double-click resets it.
+ corner_click(&mut h, corner);
+ corner_click(&mut h, corner);
+ assert_eq!(zero_point(&h), [0.0, 0.0]);
+ // Locked from the corner's context menu, the corner ignores drags and double-clicks.
+ right_click(&mut h, corner);
+ h.get_by_label("Lock Zero Point").click();
+ h.run_steps(3);
+ assert!(h.state().session.doc().unwrap().doc.settings.zero_point_locked);
+ corner_drag(&mut h, corner, dest);
+ assert_eq!(zero_point(&h), [0.0, 0.0]);
+ // Unlocked again from the same menu.
+ right_click(&mut h, corner);
+ h.get_by_label("Unlock Zero Point").click();
+ h.run_steps(3);
+ corner_drag(&mut h, corner, dest);
+ assert_ne!(zero_point(&h), [0.0, 0.0]);
+ h.state_mut().run("view.lockZeroPoint", json!({"on": true})).unwrap();
+ corner_click(&mut h, corner);
+ corner_click(&mut h, corner);
+ assert_ne!(zero_point(&h), [0.0, 0.0], "a locked zero point isn't reset");
+ }
+
+ #[test]
+ fn cmd_dragging_the_ruler_corner_makes_a_guide_each_way() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let mut h = harness(app);
+ let rect = h.state().canvas_rect.unwrap();
+ let corner = rect.min - vec2(RULER / 2.0, RULER / 2.0);
+ let dest = rect.min + vec2(120.0, 90.0);
+ let (r, at) = {
+ let app = h.state();
+ let st = app.session.active().unwrap();
+ CanvasLayout::new(&st.doc, false).spread_at(Xf::new(rect, app.view().unwrap()).to_canvas(dest)).unwrap()
+ };
+ h.event(egui::Event::ModifiersChanged(egui::Modifiers::COMMAND));
+ h.step();
+ corner_drag(&mut h, corner, dest);
+ h.event(egui::Event::ModifiersChanged(egui::Modifiers::NONE));
+ h.step();
+ let doc = h.state().session.doc().unwrap().doc.clone();
+ let guides: Vec<_> = doc.spread(r).unwrap().pages.iter().flat_map(|p| p.guides.clone()).collect();
+ assert_eq!(guides.len(), 2, "{guides:?}");
+ let pos = |o: designcraft_doc::Orientation| guides.iter().find(|g| g.orientation == o).map(|g| g.position).unwrap();
+ assert!((pos(designcraft_doc::Orientation::Horizontal) - at.y).abs() < 0.5);
+ assert!((pos(designcraft_doc::Orientation::Vertical) - at.x).abs() < 0.5);
+ assert!(guides.iter().all(|g| g.spread));
+ assert_eq!(doc.settings.zero_point, [0.0, 0.0], "the zero point stays");
+ }
+
+ #[test]
+ fn rulers_and_xy_fields_measure_from_the_zero_point_on_every_spread() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ // Spread 0: page 1; spread 1: pages 2 and 3.
+ app.run("file.new", json!({"pages": 3})).unwrap();
+ app.run("view.zeroPoint", json!({"at": [100, 50]})).unwrap();
+ app.session.prefs.dimensions_include_stroke = false;
+ let mut h = harness(app);
+ let rect = h.state().canvas_rect.unwrap();
+ for (spread, x0) in [(0usize, 136.0), (1, 736.0)] {
+ let app = h.state_mut();
+ let id = app.run("frame.create", json!({"spread": spread, "rect": [x0, 70, x0 + 50.0, 120]})).unwrap()["id"].clone();
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ // X/Y (Control, Properties and Info panels).
+ let r = crate::panels::sel_info(app).unwrap().page_rect;
+ assert!((r.x0 - (x0 - 100.0)).abs() < 1e-6 && (r.y0 - 20.0).abs() < 1e-6, "spread {spread}: {r:?}");
+ // The rulers, with that spread in view.
+ let layout = CanvasLayout::new(&app.session.active().unwrap().doc, false);
+ let slot = layout.slots[spread];
+ let v = app.view_mut().unwrap();
+ let zoom = v.zoom;
+ let c = slot.bounds.center();
+ v.origin = Point::new(c.x - rect.width() as f64 / 2.0 / zoom, c.y - rect.height() as f64 / 2.0 / zoom);
+ h.run_steps(2);
+ let app = h.state();
+ let doc = app.session.active().unwrap().doc.clone();
+ assert_eq!(current_slot(app, &layout), Some(spread));
+ let o = ruler_zero(app, &doc, &layout).unwrap();
+ assert!((o.x - slot.bounds.x0 - 100.0).abs() < 1e-6 && (o.y - slot.bounds.y0 - 50.0).abs() < 1e-6, "spread {spread}: {o:?}");
+ }
+ }
+
+ /// Screen position of spread 0's point (x, y).
+ fn screen_of(h: &Harness<'_, DesignApp>, x: f64, y: f64) -> Pos2 {
+ let app = h.state();
+ let st = app.session.active().unwrap();
+ let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
+ xf.to_screen(CanvasLayout::new(&st.doc, st.editing_parents).xf(SpreadRef::Doc(0)) * Point::new(x, y))
+ }
+
+ /// A menu row: its label, then its shortcut if it has one.
+ fn menu_row<'h>(h: &'h Harness<'_, DesignApp>, label: &'h str) -> Option<egui_kittest::Node<'h>> {
+ h.query_by(move |n| {
+ n.role() == egui::accesskit::Role::Button
+ && n.label().is_some_and(|l| l == label || l.strip_prefix(label).and_then(|r| r.strip_prefix(' ')).is_some_and(|r| !r.contains(' ')))
+ })
+ }
+
+ fn enabled(h: &Harness<'_, DesignApp>, label: &str) -> bool {
+ use egui_kittest::kittest::NodeT;
+ !menu_row(h, label).unwrap_or_else(|| panic!("no menu row {label}")).accesskit_node().is_disabled()
+ }
+
+ fn spread_items(h: &Harness<'_, DesignApp>) -> Vec<u64> {
+ h.state().session.doc().unwrap().doc.spreads[0].items.iter().map(|i| i.id.0).collect()
+ }
+
+ fn selected(h: &Harness<'_, DesignApp>) -> Vec<u64> {
+ h.state().session.doc().unwrap().selection.items.iter().map(|i| i.0).collect()
+ }
+
+ #[test]
+ fn right_clicking_an_object_selects_it_and_its_menu_arranges_it() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let a = app.run("frame.create", json!({"rect": [36, 36, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ let b = app.run("frame.create", json!({"rect": [150, 150, 300, 300]})).unwrap()["id"].as_u64().unwrap();
+ let mut h = harness(app);
+ assert_eq!(selected(&h), [b]);
+ let on_a = screen_of(&h, 60.0, 60.0);
+ right_click(&mut h, on_a);
+ assert_eq!(selected(&h), [a], "the object under the pointer is selected first");
+ // An empty frame's menu: Content, but no Fitting (nothing to fit) and no text frame entries.
+ assert!(menu_row(&h, "Content").is_some());
+ assert!(menu_row(&h, "Fitting").is_none() && menu_row(&h, "Text Frame Options…").is_none());
+ assert!(enabled(&h, "Copy") && !enabled(&h, "Paste"), "nothing copied yet: Paste is greyed");
+ menu_row(&h, "Arrange").unwrap().click();
+ h.run_steps(3);
+ menu_row(&h, "Bring to Front").unwrap().click();
+ h.run_steps(3);
+ assert_eq!(spread_items(&h), [b, a]);
+ assert!(menu_row(&h, "Arrange").is_none(), "choosing an entry closes the menu");
+ }
+
+ #[test]
+ fn right_clicking_empty_canvas_offers_paste_after_a_copy() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [36, 36, 200, 200]})).unwrap();
+ app.run("edit.copy", json!({})).unwrap();
+ app.run("edit.deselectAll", json!({})).unwrap();
+ let mut h = harness(app);
+ let empty = screen_of(&h, 400.0, 500.0);
+ right_click(&mut h, empty);
+ assert!(selected(&h).is_empty());
+ assert!(menu_row(&h, "Arrange").is_none(), "the page menu, not the object menu");
+ assert!(enabled(&h, "Paste in Place"));
+ assert!(menu_row(&h, "✓ Show/Hide Rulers").is_some(), "toggles show their state");
+ // Escape closes the menu and does nothing else.
+ h.key_press(egui::Key::Escape);
+ h.run_steps(3);
+ assert!(menu_row(&h, "Paste in Place").is_none());
+ assert_eq!(h.state().session.tool_id(), "selection");
+ right_click(&mut h, empty);
+ menu_row(&h, "Paste").unwrap().click();
+ h.run_steps(3);
+ assert_eq!(spread_items(&h).len(), 2);
+ }
+
+ #[test]
+ fn a_secondary_drag_neither_moves_marquees_nor_draws() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let a = app.run("frame.create", json!({"rect": [36, 36, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ let mut h = harness(app);
+ // A secondary-button drag between spread points.
+ let drag = |h: &mut Harness<'_, DesignApp>, from: (f64, f64), to: (f64, f64)| {
+ let (from, to) = (screen_of(h, from.0, from.1), screen_of(h, to.0, to.1));
+ h.hover_at(from);
+ h.step();
+ h.event(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
+ h.step();
+ for t in [0.25, 0.5, 0.75, 1.0] {
+ h.event(egui::Event::PointerMoved(from + (to - from) * t));
+ h.step();
+ }
+ h.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
+ h.run_steps(3);
+ };
+ let xf = |h: &Harness<'_, DesignApp>| h.state().session.doc().unwrap().doc.item(designcraft_doc::ItemId(a)).unwrap().xf;
+ let before = xf(&h);
+ // Selection tool: on the object (no move), and from empty page across it (no marquee).
+ drag(&mut h, (100.0, 100.0), (300.0, 300.0));
+ assert_eq!(xf(&h), before);
+ h.state_mut().run("edit.deselectAll", json!({})).unwrap();
+ drag(&mut h, (400.0, 400.0), (20.0, 20.0));
+ assert!(selected(&h).is_empty());
+ // Rectangle Frame tool: no frame.
+ h.state_mut().select_tool("rectangleFrame");
+ drag(&mut h, (300.0, 300.0), (500.0, 500.0));
+ assert_eq!(spread_items(&h), [a]);
+ }
+
#[test]
fn rulers_open_no_units_menu_without_a_document() {
let mut h = harness(DesignApp::new(designcraft_engine::Session::new(), crate::Services::default()));
diff --cc crates/ui-egui/src/menus.rs
index e4a6edae2,7e37c5c2b..c52bbc5b3
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@@ -2182,8 -2232,8 +2334,14 @@@ fn parse_shortcut(sc: &str) -> Option<(
pub fn shortcuts(app: &mut DesignApp, ctx: &egui::Context) {
// Only a focused text field takes the keys: the canvas (or a button) having focus after a click
// must not swallow tool shortcuts until Esc clears it.
- // While an IME composes at the text caret, the keyboard is its own.
- if ctx.text_edit_focused() || app.ui.dialog.is_some() || app.ui.palette.is_some() || app.session.tool_composing() {
- // An open canvas context menu takes the keys (Escape closes it), as a native menu would.
- if ctx.text_edit_focused() || app.ui.dialog.is_some() || app.ui.palette.is_some() || crate::canvas::context_menu_open(ctx) {
++ // While an IME composes at the text caret, the keyboard is its own. An open canvas context menu
++ // takes the keys (Escape closes it), as a native menu would.
++ if ctx.text_edit_focused()
++ || app.ui.dialog.is_some()
++ || app.ui.palette.is_some()
++ || app.session.tool_composing()
++ || crate::canvas::context_menu_open(ctx)
++ {
return;
}
let typing = app.session.wants_text();