diff --git a/crates/ui-egui/src/chrome/tabs.rs b/crates/ui-egui/src/chrome/tabs.rs index 506b149fee..9278b8baf3 100644 --- a/crates/ui-egui/src/chrome/tabs.rs +++ b/crates/ui-egui/src/chrome/tabs.rs @@ -339,7 +339,9 @@ pub fn isolation_bar(app: &mut VectorcraftApp, ui: &mut Ui, area: egui::Rect) { } let bar = egui::Rect::from_min_size(area.min, vec2(area.width(), 24.0)); // Keeps the pointer off the canvas; not focusable (`click_and_drag` is), so Tab skips it. - ui.interact(bar, ui.scope_id().with("iso-bar"), Sense::CLICK | Sense::DRAG); + // A click on it, the current object's name included, outside the back arrow, the crumbs of + // the levels above and the pattern buttons leaves isolation mode. + let background = ui.interact(bar, ui.scope_id().with("iso-bar"), Sense::CLICK | Sense::DRAG); ui.painter().rect_filled(bar, 0.0, t.panel); let back = egui::Rect::from_min_size(bar.min + vec2(6.0, 3.0), vec2(18.0, 18.0)); let bresp = ui.interact(back, ui.scope_id().with("iso-back"), Sense::click()); @@ -406,12 +408,38 @@ pub fn isolation_bar(app: &mut VectorcraftApp, ui: &mut Ui, area: egui::Rect) { }); } } + // A click on the background leaves isolation mode altogether, symbol editing mode included. + // While a pattern is edited it does nothing: Save a Copy, Done and Cancel end pattern editing. + let leave = background.clicked() && nav_cmd.is_none() && pattern_cmd.is_none() && pattern_edit.is_none(); if let Some((cmd, params)) = nav_cmd { app.run(cmd, params).ok(); } if let Some(cmd) = pattern_cmd { app.run(cmd, json!({})).ok(); } + if leave { + leave_isolation(app); + } + } +} + +/// Runs `object.exitIsolation` until the current document is out of isolation mode. Leaving symbol +/// editing mode from a group isolated inside the symbol's art first goes back to the art, and leaving +/// the mode restores the isolation it was entered from; each of these is left in turn. It stops at +/// pattern editing, which only its own buttons end, and when a step fails or changes nothing. +fn leave_isolation(app: &mut VectorcraftApp) { + // Each step leaves one level; a document has far fewer levels than this. + const MAX_STEPS: usize = 64; + let state = |app: &VectorcraftApp| { + app.session + .active() + .map(|d| (d.isolation, d.doc.symbol_edit.as_ref().map(|e| e.layer), d.doc.mask_edit.is_some(), d.doc.pattern_edit.is_some())) + }; + for _ in 0..MAX_STEPS { + let Some(before) = state(app) else { return }; + if before.0.is_none() || before.3 || app.run("object.exitIsolation", json!({})).is_err() || state(app) == Some(before) { + return; + } } } diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index f1c63eafb4..b0cbecd7d3 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -1508,6 +1508,155 @@ fn isolation_bar_navigation_and_back_button_steps_up() { assert_eq!(app.session.active().unwrap().isolation, Some(NodeId(g2))); } +/// Headless frames of the isolation bar over a 1200 × 700 canvas for one pointer gesture: a press +/// at `from`, a move to `to` and a release there. `from == to` is a click. +fn isolation_bar_gesture(app: &mut crate::VectorcraftApp, ctx: &egui::Context, from: egui::Pos2, to: egui::Pos2) { + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 700.0)); + let press = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + for events in [vec![egui::Event::PointerMoved(from)], vec![press(from, true)], vec![egui::Event::PointerMoved(to)], vec![press(to, false)]] { + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| { + super::isolation_bar(app, ui, screen); + }); + out.textures_delta.clear(); + } +} + +/// A context for `isolation_bar_gesture`. +fn isolation_bar_context() -> egui::Context { + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + egui_extras::install_image_loaders(&ctx); + ctx +} + +/// A click on the isolation bar's empty space leaves nested isolation mode altogether, selects the +/// isolated object as Exit Isolation Mode does and adds no undo step. A drag across the bar does not +/// leave it. +#[test] +fn isolation_bar_background_click_exits_nested_isolation() { + use vectorcraft_doc::NodeId; + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + let rect = |app: &mut crate::VectorcraftApp, x: f64| { + app.run("shape.rectangle", json!({"x": x, "y": 10, "width": 30, "height": 20})).unwrap()["id"].as_u64().unwrap() + }; + let (a, b) = (rect(&mut app, 10.0), rect(&mut app, 50.0)); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + let g1 = app.run("object.group", json!({})).unwrap()["id"].as_u64().unwrap(); + let c = rect(&mut app, 90.0); + app.run("select.set", json!({"ids": [g1, c]})).unwrap(); + app.run("object.group", json!({})).unwrap(); + app.run("object.isolate", json!({"id": a})).unwrap(); + let ctx = isolation_bar_context(); + let empty = egui::pos2(700.0, 12.0); + isolation_bar_gesture(&mut app, &ctx, empty, egui::pos2(900.0, 14.0)); + assert_eq!(app.session.active().unwrap().isolation, Some(NodeId(a)), "a drag across the bar stays in isolation mode"); + let steps = app.session.doc().unwrap().history.undo.len(); + isolation_bar_gesture(&mut app, &ctx, empty, empty); + let st = app.session.active().unwrap(); + assert_eq!((st.isolation, st.selection.objects.clone()), (None, vec![NodeId(a)]), "the click leaves isolation mode"); + assert_eq!(app.session.doc().unwrap().history.undo.len(), steps, "no undo step"); +} + +/// While a pattern is edited, a click on the isolation bar's empty space leaves pattern editing +/// open; the back arrow still ends it as Done does. +#[test] +fn isolation_bar_background_click_leaves_pattern_edit_open() { + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + let f = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [f]})).unwrap(); + app.run("object.pattern.make", json!({"name": "Dots", "width": 20, "height": 20})).unwrap(); + assert!(app.session.active().unwrap().doc.pattern_edit.is_some()); + let ctx = isolation_bar_context(); + let empty = egui::pos2(500.0, 12.0); + isolation_bar_gesture(&mut app, &ctx, empty, empty); + let st = app.session.active().unwrap(); + assert!(st.doc.pattern_edit.is_some() && st.isolation.is_some(), "pattern editing stays open"); + let back = egui::pos2(15.0, 12.0); + isolation_bar_gesture(&mut app, &ctx, back, back); + let st = app.session.active().unwrap(); + assert!(st.doc.pattern_edit.is_none() && st.isolation.is_none(), "the back arrow ends pattern editing"); +} + +/// While an opacity mask is edited, a click on the isolation bar's empty space stops editing the +/// mask as Exit Isolation Mode does: the masked object is selected again. +#[test] +fn isolation_bar_background_click_stops_mask_editing() { + use vectorcraft_doc::NodeId; + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 300})).unwrap(); + let obj = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 200, "height": 200})).unwrap()["id"].as_u64().unwrap(); + let m = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 100, "height": 200})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [obj, m]})).unwrap(); + app.run("transparency.makeOpacityMask", json!({})).unwrap(); + app.run("transparency.editOpacityMask", json!({})).unwrap(); + assert!(app.session.active().unwrap().doc.mask_edit.is_some()); + let ctx = isolation_bar_context(); + let empty = egui::pos2(700.0, 12.0); + isolation_bar_gesture(&mut app, &ctx, empty, empty); + let st = app.session.active().unwrap(); + assert!(st.doc.mask_edit.is_none() && st.isolation.is_none(), "mask editing ends"); + assert_eq!(st.selection.objects, vec![NodeId(obj)]); +} + +/// In symbol editing mode, a click on the isolation bar's empty space leaves the mode, also while a +/// group inside the symbol's art is isolated, and the symbol keeps the art drawn while editing. +#[test] +fn isolation_bar_background_click_leaves_nested_symbol_editing() { + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap(); + app.run("symbol.new", json!({"name": "Box"})).unwrap(); + app.run("symbol.edit", json!({"name": "Box"})).unwrap(); + let a = app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + let b = app.run("shape.rectangle", json!({"x": 130, "y": 100, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + let g = app.run("object.group", json!({})).unwrap()["id"].as_u64().unwrap(); + app.run("object.isolate", json!({"id": g})).unwrap(); + let ctx = isolation_bar_context(); + let empty = egui::pos2(700.0, 12.0); + isolation_bar_gesture(&mut app, &ctx, empty, empty); + let st = app.session.active().unwrap(); + assert!(st.doc.symbol_edit.is_none() && st.isolation.is_none(), "symbol editing mode ends"); + let symbol = st.doc.symbols.iter().find(|s| s.name == "Box").expect("the symbol"); + assert!(symbol.art.children().is_some_and(|c| c.len() >= 2), "the edit reached the symbol"); + // Symbol editing entered while a group was isolated: the click leaves that isolation too. + let c = app.run("shape.rectangle", json!({"x": 200, "y": 150, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + let d = app.run("shape.rectangle", json!({"x": 250, "y": 150, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [c, d]})).unwrap(); + let h = app.run("object.group", json!({})).unwrap()["id"].as_u64().unwrap(); + app.run("object.isolate", json!({"id": h})).unwrap(); + app.run("symbol.edit", json!({"name": "Box"})).unwrap(); + assert!(app.session.active().unwrap().doc.symbol_edit.is_some()); + isolation_bar_gesture(&mut app, &ctx, empty, empty); + let st = app.session.active().unwrap(); + assert!(st.doc.symbol_edit.is_none() && st.isolation.is_none(), "the isolation from before symbol editing ends too"); +} + +/// A click on the current object's name at the end of the breadcrumbs, which is not a link, leaves +/// isolation mode as a click on the bar's empty space does. +#[test] +fn isolation_bar_click_on_the_current_name_exits() { + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + let a = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("object.isolate", json!({"id": a})).unwrap(); + let ctx = isolation_bar_context(); + // The crumbs are "Layer 1 › "; the leaf's name starts after the layer crumb and separator. + let layer = app.session.active().unwrap().doc.ancestry(vectorcraft_doc::NodeId(a)).unwrap()[0]; + let layer_name = app.session.active().unwrap().doc.node(layer).unwrap().display_name(); + let mut start = 0.0; + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + let width = |s: &str| ui.painter().layout_no_wrap(s.to_string(), egui::FontId::proportional(12.0), egui::Color32::WHITE).size().x; + start = 30.0 + width(&layer_name) + 6.0 + width("›") + 6.0; + }); + out.textures_delta.clear(); + let leaf = egui::pos2(start + 4.0, 12.0); + isolation_bar_gesture(&mut app, &ctx, leaf, leaf); + assert_eq!(app.session.active().unwrap().isolation, None); +} + /// Tab goes to the isolation bar's back button and breadcrumbs and does not stop on the bar /// behind them, which only keeps the pointer off the canvas. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 04572978e1..4444f5fae2 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1100,6 +1100,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - The Control bar's underlined Transform link opens the Transform panel in a popover under it (reference point, X/Y/W/H, Rotate and Shear with their icons and angle presets, flips, shape properties, Scale Corners and Scale Strokes & Effects), as its Stroke link does the Stroke panel; X/Y/W/H also show inline while the bar has room. The reference point locator is nine squares, the outer eight joined around the box. As VectorCraft's own keyboard rule, the locator is one tab stop in the Control bar popover, the Transform panel, the Properties panel and the dialogs, the Arrange Tools dialogs included. While it has the focus it shows an outline, and ←, →, ↑ and ↓ move the reference point one square, stopping at the edges (`the_reference_point_grid_is_one_tab_stop`, `arrow_keys_move_the_reference_point`, `the_reference_point_locator_is_one_tab_stop_and_arrows_move_it`). - In isolation mode the Control bar has an Exit Isolation Mode button (`object.exitIsolation`), except while a pattern is edited. Outside isolation mode, with one group, compound path, path, image, mesh or placed file selected, it has an Isolate Selected Object button (`object.isolate`), which also isolates a path inside a group that Direct Selection selected. - While an opacity mask is edited, Exit Isolation Mode (Esc, the isolation bar's back arrow, the Control bar's button, and the Layers panel menu's and canvas context menu's Exit Isolation Mode) leaves mask editing as Stop Editing Opacity Mask does, in one undo step: the mask keeps the edits, and the masked object is selected. While a pattern is edited, the Exit Isolation Mode item of the Layers panel menu and of the canvas context menu saves the pattern and leaves pattern editing, as Done does. + - A click anywhere on the isolation bar, the isolated object's name included, outside its back arrow, the breadcrumbs of the levels above and its buttons leaves isolation mode altogether, nested isolation included, as Exit Isolation Mode does ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs4/illustrator_cs4_help.pdf#page=207)). As VectorCraft's own rules, the click stops editing an opacity mask, leaves symbol editing mode even while a group inside the symbol's art is isolated, together with the isolation the mode was entered from, and does nothing while a pattern is edited; a drag across the bar does not leave (`isolation_bar_background_click_exits_nested_isolation`). - Numeric spinner arrows keep stepping while held with the mouse past the click timeout and stop on release (#6307; `a_held_spinner_arrow_repeats`). - Object › Vector Halftone keeps the selection box and hides selection marks on the temporary dots during Preview; turning Preview off or cancelling restores the original selection marks (#6369). - Tab shows and hides the panels (in the Type tool it types a tab) without moving the keyboard focus onto a field, so the next shortcut or letter still works; in dialogs and panel fields it moves between fields, one press each — a numeric field's scrub label is not a tab stop of its own, and the Transform panel's, Properties panel's and Control bar's W/H link comes after the fields it sits between (`one_tab_moves_from_a_field_to_the_next`). A field's up/down spinner, the chevron that opens its presets (Stroke Weight, font size, Rotate, Export for Screens' scale) and the Transparency row's opacity slider chevron are not tab stops either. Alt+↓ with no other modifier in a field with presets opens them with the keyboard focus on the chosen one, instead of stepping the field down; Enter picks the focused preset without pressing a dialog's OK, and after a pick or Escape the field has the keyboard focus again (`tab_goes_from_field_to_field_past_the_spinner_and_the_preset_chevron`, `tab_goes_from_the_opacity_field_past_its_slider_chevron`, `alt_down_opens_a_fields_presets_for_the_keyboard`, `escape_closes_a_fields_presets_and_returns_to_the_field`).