Merge pull request #2583 from dotCooCoo/fix/presentation-mode-non-editable

View: in Presentation Mode no key but ←, → and Escape acts, and no context menu opens
This commit is contained in:
BFlat
2026-10-17 13:41:06 +07:00
committed by GitHub
5 changed files with 135 additions and 45 deletions
+12 -3
View File
@@ -236,7 +236,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let xf = Xf::new(rect, &v);
let origin_preview = if app.ui.view.rulers && app.ui.screen_mode < 3 { ruler_input(app, ui, full, rect, &xf) } else { None };
panel_drop(app, ui, &resp, &xf);
context_menu(app, &resp, &xf);
// In Presentation Mode a right click or a long touch opens no context menu.
if app.ui.screen_mode < 3 {
context_menu(app, &resp, &xf);
}
let painter = ui.painter_at(rect);
let Some(st) = app.session.active() else { return };
let doc = st.doc.clone();
@@ -536,7 +539,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
} else {
None
};
let cur = if let Some(c) = view_cursor.or_else(|| app.hover_doc.map(|p| app.session.cursor(p, mods(m, space), view_info))) {
// In Presentation Mode the pointer is the default one, with no tool cursor.
let tool_cursor =
(app.ui.screen_mode < 3).then(|| view_cursor.or_else(|| app.hover_doc.map(|p| app.session.cursor(p, mods(m, space), view_info))));
let cur = if let Some(c) = tool_cursor.flatten() {
let painter = ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Tooltip, egui::Id::new("tool-cursor")));
// The loaded place cursor carries the file's thumbnail.
if app.session.tool_id() == "place"
@@ -1210,7 +1216,10 @@ fn touch_gestures(app: &mut VectorcraftApp, ui: &Ui, rect: egui::Rect, view: vec
}
}
ui.data_mut(|d| d.insert_temp(key, taps));
if let Some(cmd) = tap {
// In Presentation Mode a tap of two or three fingers undoes or redoes nothing.
if let Some(cmd) = tap
&& app.ui.screen_mode < 3
{
crate::menus::invoke(app, cmd, serde_json::json!({}));
}
}
+2 -2
View File
@@ -1242,8 +1242,8 @@ pub fn run_ui_command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
"view.screenMode" => {
app.ui.screen_mode = match p.get("mode").and_then(Value::as_u64) {
Some(m) => m.min(3) as u8,
// F cycles the three screen modes; from Presentation Mode (not in the cycle) it
// goes back to Normal.
// F cycles the three screen modes. Without a mode, the command also goes from
// Presentation Mode (not in the cycle) back to Normal.
None if app.ui.screen_mode >= 2 => 0,
None => app.ui.screen_mode + 1,
};
+47 -26
View File
@@ -263,6 +263,10 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) {
}
return;
}
if app.ui.screen_mode == 3 {
presentation_keys(app, ctx, escape_pair);
return;
}
let typing = ctx.egui_wants_keyboard_input();
// Escape closes Edit Toolbar's drawer first (egui drops a drag from it on Escape already).
if app.ui.tools_drawer && !typing && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) {
@@ -287,10 +291,7 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) {
ctx.input_mut(|i| i.consume_key(Modifiers::NONE, k));
}
if k == Key::Escape && !busy && !claimed {
// Escape leaves Presentation Mode first: it hides the menus and panels.
if app.ui.screen_mode == 3 {
let _ = app.run("view.presentation", json!({}));
} else if app.session.active().is_some_and(|d| d.doc.pattern_edit.is_some()) {
if app.session.active().is_some_and(|d| d.doc.pattern_edit.is_some()) {
let _ = app.run("object.pattern.done", json!({}));
} else if app.session.active().is_some_and(|d| d.isolation.is_some()) {
let _ = app.run("object.exitIsolation", json!({}));
@@ -332,28 +333,6 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) {
if ctx.input(|i| i.key_pressed(Key::Tab)) {
ctx.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
}
// In Presentation Mode, ← and → go to the previous and the next artboard. Every arrow key press
// is removed from the input here, so no arrow key moves the selection or is sent to the tool.
if app.ui.screen_mode == 3 {
let mut steps = vec![];
ctx.input_mut(|i| {
i.events.retain(|e| match e {
egui::Event::Key { key: Key::ArrowLeft, pressed: true, .. } => {
steps.push(false);
false
}
egui::Event::Key { key: Key::ArrowRight, pressed: true, .. } => {
steps.push(true);
false
}
egui::Event::Key { key: Key::ArrowUp | Key::ArrowDown, pressed: true, .. } => false,
_ => true,
})
});
for next in steps {
presentation_step(app, next);
}
}
// Type tool editing: text, IME composition and editing keys go to the tool.
if app.session.tool_wants_text() {
type_text(app, ctx);
@@ -637,6 +616,48 @@ fn escape_resets_rotation(app: &VectorcraftApp, ctx: &egui::Context, second: boo
&& !crate::canvas::ruler_origin_dragging(ctx)
}
/// The keys in Presentation Mode, where nothing is edited: Escape leaves the mode, and ← and → go to
/// the previous and the next artboard ([`presentation_step`]). Every other key press, the text it
/// types and the clipboard keys are removed from the input, so no shortcut, tool or field acts on
/// them. The macOS menu bar's key equivalents arrive as key presses too ([`crate::native_menu`]).
fn presentation_keys(app: &mut VectorcraftApp, ctx: &egui::Context, escape_pair: Option<bool>) {
let (mut leave, mut steps) = (false, vec![]);
ctx.input_mut(|i| {
i.events.retain(|e| match e {
egui::Event::Key { key: Key::Escape, pressed: true, .. } => {
leave = true;
false
}
egui::Event::Key { key: Key::ArrowLeft, pressed: true, .. } => {
steps.push(false);
false
}
egui::Event::Key { key: Key::ArrowRight, pressed: true, .. } => {
steps.push(true);
false
}
egui::Event::Key { pressed: true, .. }
| egui::Event::Text(_)
| egui::Event::Ime(_)
| egui::Event::Copy
| egui::Event::Cut
| egui::Event::Paste(_) => false,
_ => true,
})
});
for next in steps {
presentation_step(app, next);
}
if leave {
let _ = app.run("view.presentation", json!({}));
// The Escape that left the mode can start a pair, as in `handle`.
if escape_pair.is_some() && !egui::Popup::is_any_open(ctx) {
let now = ctx.input(|i| i.time);
ctx.data_mut(|d| d.insert_temp(escape_pair_id(), now));
}
}
}
/// Go to the next artboard (`next`) or the previous one with `view.goToArtboard`, as the status bar
/// navigator's Next and Previous buttons do, for the arrow keys and a click in Presentation Mode.
/// On the last artboard a step forward leaves the view as it is, and so does a step back on the
+72 -13
View File
@@ -1,6 +1,7 @@
//! Screen modes and Presentation Mode (#472): Escape leaves Presentation Mode, F cycles the three
//! screen modes, and no screen mode is saved with the preferences. In Presentation Mode, ← and →
//! and a click go between the artboards.
//! and a click go between the artboards, no other key acts, a right click opens no context menu and
//! the pointer is the default one.
use serde_json::json;
use vectorcraft_engine::Session;
@@ -8,7 +9,7 @@ use vectorcraft_engine::Session;
use crate::VectorcraftApp;
/// One headless frame of the whole window with `events`.
fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) {
fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) -> egui::FullOutput {
let raw =
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), events, ..Default::default() };
let mut out = ctx.run_ui(raw, |ui| {
@@ -16,6 +17,7 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>
app.ui(ui);
});
out.textures_delta.clear();
out
}
fn escape() -> Vec<egui::Event> {
@@ -119,8 +121,8 @@ fn arrow_keys_go_between_artboards_in_presentation_mode() {
/// Next does, and the tool gets no press: a click on the rectangle with the Selection tool selects
/// nothing, and with the Rectangle tool a drag draws nothing and a click pressed and released in
/// one frame opens no dialog. A drag, also with the middle button or with Space held, leaves the
/// view as it is, the press that closes the context menu goes to no other artboard, and on the last
/// artboard a click leaves the view as it is.
/// view as it is, a right click opens no context menu and goes to no other artboard, and on the
/// last artboard a click leaves the view as it is.
#[test]
fn a_click_goes_to_the_next_artboard_in_presentation_mode() {
let ctx = egui::Context::default();
@@ -136,10 +138,8 @@ fn a_click_goes_to_the_next_artboard_in_presentation_mode() {
for e in [vec![right(true)], vec![right(false)], vec![]] {
frame(&mut app, &ctx, e);
}
assert!(egui::Popup::is_any_open(&ctx), "a right click opens the context menu");
click(&mut app, &ctx, middle - egui::vec2(150.0, 0.0));
assert!(!egui::Popup::is_any_open(&ctx), "a click closes it");
assert_eq!(view(&app).0, 1, "the click that closes the context menu");
assert!(!egui::Popup::is_any_open(&ctx), "a right click opens no context menu");
assert_eq!(view(&app).0, 1, "a right click");
app.select_tool("rectangle");
let button = |button, pos, pressed| egui::Event::PointerButton { pos, button, pressed, modifiers: Default::default() };
let to = middle + egui::vec2(80.0, 60.0);
@@ -171,8 +171,8 @@ fn a_click_goes_to_the_next_artboard_in_presentation_mode() {
assert!(unchanged(&app), "nothing was selected or drawn");
}
/// In Presentation Mode a tap goes to the next artboard. A tap of two fingers undoes (Enable Touch
/// Gestures) and goes to no other artboard.
/// In Presentation Mode a tap goes to the next artboard. A tap of two fingers, which undoes in the
/// other screen modes (Enable Touch Gestures), undoes nothing and goes to no other artboard.
#[test]
fn a_tap_goes_to_the_next_artboard_in_presentation_mode() {
let ctx = egui::Context::default();
@@ -192,16 +192,75 @@ fn a_tap_goes_to_the_next_artboard_in_presentation_mode() {
tap(&mut app, 1);
assert_eq!((view(&app).0, objects(&app)), (1, 1), "a tap");
tap(&mut app, 2);
assert_eq!((view(&app).0, objects(&app)), (1, 0), "two fingers undo the rectangle");
assert_eq!((view(&app).0, objects(&app)), (1, 1), "two fingers undo nothing");
}
/// In Presentation Mode no key but ←, → and Escape acts: Cmd/Ctrl+A selects nothing, P and V pick
/// no tool, Delete and Backspace delete nothing, Cmd/Ctrl+Z undoes nothing, Enter opens no dialog,
/// Tab hides no panel and F keeps the screen mode. Escape still leaves the mode, also with a tool
/// that claims Escape.
#[test]
fn no_other_key_works_in_presentation_mode() {
use egui::{Key, Modifiers};
let ctx = egui::Context::default();
let mut app = presenting(&ctx);
// A press and release of `key` with `modifiers` held, and the text it types.
let press = |key, modifiers: Modifiers, text: Option<&str>| {
let k = |pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers };
let mut events = vec![egui::Event::ModifiersChanged(modifiers), k(true)];
events.extend(text.map(|t| egui::Event::Text(t.into())));
events.extend([k(false), egui::Event::ModifiersChanged(Modifiers::NONE)]);
events
};
app.run("select.none", json!({})).unwrap();
frame(&mut app, &ctx, press(Key::A, Modifiers::COMMAND, None));
assert!(app.session.active().unwrap().selection.objects.is_empty(), "Cmd/Ctrl+A selected the rectangle");
app.run("select.all", json!({})).unwrap();
let unchanged = snapshot(&app);
let panels = (app.ui.dock, app.ui.toolbar);
for (what, events) in [
("Delete", press(Key::Delete, Modifiers::NONE, None)),
("Backspace", press(Key::Backspace, Modifiers::NONE, None)),
("Cmd/Ctrl+Z", press(Key::Z, Modifiers::COMMAND, None)),
("Enter", press(Key::Enter, Modifiers::NONE, None)),
("Tab", press(Key::Tab, Modifiers::NONE, None)),
("F", press(Key::F, Modifiers::NONE, Some("f"))),
("P", press(Key::P, Modifiers::NONE, Some("p"))),
] {
frame(&mut app, &ctx, events);
assert!(unchanged(&app), "{what} changed the document, the selection or the undo steps");
let state = (app.session.tool_id(), app.ui.dialog.is_none(), app.ui.screen_mode, (app.ui.dock, app.ui.toolbar));
assert_eq!(state, ("selection", true, 3, panels), "{what}");
}
app.select_tool("rectangle");
frame(&mut app, &ctx, press(Key::V, Modifiers::NONE, Some("v")));
assert_eq!(app.session.tool_id(), "rectangle", "V");
// The Intertwine tool claims Escape in the other screen modes.
app.select_tool("intertwine");
frame(&mut app, &ctx, escape());
assert_eq!(app.ui.screen_mode, 0, "Escape leaves Presentation Mode");
}
/// In Presentation Mode the pointer over the canvas is the system's default pointer, not the
/// tool's cursor.
#[test]
fn the_pointer_is_the_default_one_in_presentation_mode() {
let ctx = egui::Context::default();
let mut app = presenting(&ctx);
app.select_tool("rectangle");
let middle = app.canvas_rect.unwrap().center();
let out = frame(&mut app, &ctx, vec![egui::Event::PointerMoved(middle)]);
assert_eq!(out.platform_output.cursor_icon, egui::CursorIcon::Default);
assert!(out.platform_output.cursor_image.is_none(), "no tool cursor bitmap");
}
#[test]
fn f_cycles_the_screen_modes_and_leaves_presentation_mode() {
fn f_cycles_the_screen_modes_and_the_command_leaves_presentation_mode() {
let mut app = VectorcraftApp::new(Session::new(), crate::Services::default());
let modes: Vec<u64> = (0..4).map(|_| app.run("view.screenMode", json!({})).unwrap().as_u64().unwrap()).collect();
assert_eq!(modes, [1, 2, 0, 1]);
app.run("view.presentation", json!({})).unwrap();
assert_eq!(app.run("view.screenMode", json!({})).unwrap(), json!(0), "from Presentation Mode, F goes back to Normal");
assert_eq!(app.run("view.screenMode", json!({})).unwrap(), json!(0), "from Presentation Mode, view.screenMode goes back to Normal");
}
#[test]
+2 -1
View File
@@ -519,8 +519,9 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Drawing aids:** Smart Guides and snapping (moving, with the Selection, Group Selection or Direct Selection tool, and resizing by the bounding-box handles with the Selection or Free Transform tool, Shift and Alt too: the dragged corner or side lands on the other objects' anchors and centres ("anchor", "center") or lines up with their edges and centres (a line and "align"); with Smart Guides › Spacing Guides, a moved selection that lines up with nothing along an axis lands as far from its neighbour as two other objects of its row or column are apart, or halfway between its two neighbours, the equal gaps marked; with View › Snap to Grid on, a moved selection lands on the grid instead, by whichever of its edges or its centre is nearest a gridline on each axis, #740; the Rotate, Scale, Shear and Reflect tools drag from the anchor they grab and snap the pointer the same way, so a corner dragged onto another object's anchor scales exactly onto it, #482; anchors dragged with Direct Selection: the one pressed on lands on other anchors, its own path's that stay put among them, on path segments or in line with them, the others following, Shift keeps 45° steps, and with Smart Guides off Snap to Point pulls it onto anchors; the Artboard tool snaps artboards, and their bleed, to other artboards, bleeds and art, the grid or whole pixels while moving, copying and resizing them, and the Transform panel shows and edits the active artboard's X/Y/W/H; drawn points, #506: hovering shows where the press goes, the point lands on the other objects' anchors, centres and paths ("anchor", "center", "path") or lines up with their anchors, edges and centres ("align"), the Pen's on the path being drawn too, near a construction guide through the anchor before it on that guide (Preferences › Smart Guides › Construction Guides and Angles), and with Shift kept to its 45° step or a square's diagonal it slides along that way into line; the targets are gathered once per document state, from the art in the window, and the anchors, centres and lines near the pointer are found by bisection, so hovering never rescans the document), guides dragged out of the rulers (#451: they snap as moved guides do, Shift to the ruler's ticks; with the Artboard tool they are artboard guides, which run across their artboard only and move, copy and delete with it, `guide.add {artboard}`) that the Selection, Direct Selection and Group Selection tools then pick and drag (#414: the selected guides highlight and move together, Alt copies them, Shift snaps the dragged one to the ticks, otherwise it snaps to pixels, the grid or the edges, centres (so the sides' midpoints) and anchors of the art and the artboards, or with Smart Guides off Snap to Point pulls it onto anchors; Shift-clicked they join the selected art, and Shift-added art keeps them, so guides and art are selected together in either order, Delete then deleting both in one step; the arrow keys nudge them, Delete deletes them, dragging one back onto its ruler deletes it, Lock Guides and Hide Guides leave them alone; `guide.list`, `guide.select`, `guide.move` and `guide.remove` reach agents), a right-click on either ruler or the origin box to pick the document's units (the current one checked; `document.setUnits`, one undo step, #528), and Draw Normal / Behind / Inside modes. Smart Guides: a point drawn with the Pen or a shape tool, and an anchor dragged with Direct Selection, snaps to where paths and ruler guides cross, labelled "intersect" (#1658, part of #1602; a moved selection's own anchors don't).
- **Artboard click-to-fit (#1227):** a plain click fits the topmost editable object or group to a new artboard, including its stroke like Fit to Selected Art, and makes the new artboard active. Art and its selection stay unchanged; creation is one undo step. Handles, modified clicks, drags, Escape and tool changes retain their meaning. Tested inside an artboard and on the pasteboard (`crates/engine/tests/artboard_click.rs`); the public [CS6 Printing Guide](https://helpx.adobe.com/content/dam/help/en/indesign/pdf/CS6_PrintGuide.pdf) documents the object-click gesture. This legacy gesture adds evidence without regrading the 2026 canvas controls.
- **Rotated views:** with the view rotated, Fit Artboard in Window, Fit All in Window and the status bar's artboard navigator fit the artboard or the art as the view turns it, and a Zoom tool marquee (Animated Zoom or GPU Performance off) zooms to the area dragged across. Ruler guides on no artboard turn with the view. The canvas draws the selection marquee where the tools select, Show Hidden Characters draws the marks of type partly inside the canvas, the Contextual Task Bar stays under the selection, and the Navigator's red box outlines what the window shows.
- **Views:** the status bar's artboard navigator (first, previous, next, last; `view.goToArtboard`) goes to an artboard, fits it and synchronizes the Artboard tool selection when that tool is active; ordinary object selection is preserved. Actual Next-button regressions cover keyboard/Properties deletion and Undo in `chrome.rs`. Fit Artboard in Window and Actual Size show the navigator's artboard. The Artboards panel highlights that active artboard: clicking a row makes it active (the Artboard tool's too, while it is chosen) as does clicking an artboard with the Artboard tool, double-clicking its number also fits it in the window and double-clicking its name renames it. Duplicate Artboards, or a row dragged onto New Artboard, copies the artboard with its art (#446). Escape leaves Presentation Mode, F from it goes back to Normal Screen Mode, and the screen mode isn't saved with the preferences: the app always starts in Normal Screen Mode with its menus and panels (#472). View › Pixel Preview shows the art as the document pixels it rasterizes to, one per point and hard-edged when magnified, turning with a rotated view (it used to draw the smooth vectors, with only the pixel grid over them). In Outline view a template layer keeps drawing in Preview, dimmed, so a picture placed to be traced stays visible under the outlines (#1505, fixes #1486).
- **Views:** the status bar's artboard navigator (first, previous, next, last; `view.goToArtboard`) goes to an artboard, fits it and synchronizes the Artboard tool selection when that tool is active; ordinary object selection is preserved. Actual Next-button regressions cover keyboard/Properties deletion and Undo in `chrome.rs`. Fit Artboard in Window and Actual Size show the navigator's artboard. The Artboards panel highlights that active artboard: clicking a row makes it active (the Artboard tool's too, while it is chosen) as does clicking an artboard with the Artboard tool, double-clicking its number also fits it in the window and double-clicking its name renames it. Duplicate Artboards, or a row dragged onto New Artboard, copies the artboard with its art (#446). Escape leaves Presentation Mode, `view.screenMode` from it goes back to Normal Screen Mode, and the screen mode isn't saved with the preferences: the app always starts in Normal Screen Mode with its menus and panels (#472). View › Pixel Preview shows the art as the document pixels it rasterizes to, one per point and hard-edged when magnified, turning with a rotated view (it used to draw the smooth vectors, with only the pixel grid over them). In Outline view a template layer keeps drawing in Preview, dimmed, so a picture placed to be traced stays visible under the outlines (#1505, fixes #1486).
In Presentation Mode, → and ← go to the next and the previous artboard, and a click anywhere goes to the next one, as the status bar navigator's Next and Previous do (`view.goToArtboard`): on the last artboard → and a click leave the view as it is, and so does ← on the first. The arrow keys do not move the selection there, and the tool does not receive a click, so a click selects and draws nothing (behavior reference: [View artwork](https://helpx.adobe.com/illustrator/using/viewing-artwork.html)).
In Presentation Mode no key press other than ←, → and Escape runs a command or reaches the tool (tool keys, Delete, Enter, Tab, F, Shift+F and every command shortcut, the macOS menu bar's key equivalents included), a right click or a long touch opens no context menu, a tap of two or three fingers undoes or redoes nothing, and the pointer over the canvas is the default one instead of the tool's cursor.
Align to Artboard uses the active artboard, the one the Artboards panel highlights (`object.align {artboard}`). A press with a selection tool inside an artboard makes that artboard active; with the Selection tool, a Shift-click on an empty spot inside an artboard makes it active and keeps the selection. One selected object is aligned to the active artboard too, whatever Align To says (a lone object is never the key object). When an action plays, its Align to Artboard, All on Active Artboard, Paste in Place, Paste in Front and Paste in Back steps that name no artboard use the artboard that is active then.
Choosing the Artboard tool (Shift+O, its toolbar button, or Edit Artboards in Properties or Document Setup) starts it on the active artboard: the canvas outlines that artboard, and Delete, Cut, Copy, the Transform panel and Artboard Options act on it.
In the Artboards panel, a click on the active artboard's options icon, or a double-click on another row's icon, opens Artboard Options for that row's artboard, and the panel menu's Artboard Options… opens it for the active artboard (part of #1876). Both used to choose the Artboard tool instead. Opened while another tool is in use, the dialog moves the art with a new X or Y when the Artboard tool's Move Artwork with Artboard option is on.