mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 14:34:34 +00:00
Merge remote-tracking branch 'origin/main' into HEAD
# Conflicts: # docs/gaps.md # docs/roadmap.md # docs/target-app-parity.md # docs/ui-parity.md
This commit is contained in:
@@ -2169,4 +2169,6 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"",
|
||||
"{plane?: left|right|ground (default: the active plane)} open the plane's options, as double-clicking its plane widget does (dialog `perspectivePlane`: location (pt along the plane's normal), objects: none|move|copy): OK runs perspective.plane.move",
|
||||
),
|
||||
("ui.findAndReplace", "Find and Replace…", "", "{} open the Find and Replace dialog (Edit › Find and Replace…; dialog `findReplace`)"),
|
||||
("ui.retype", "Retype", "", "{} open the Retype panel (Window › Retype) or start Retype"),
|
||||
];
|
||||
|
||||
@@ -1249,6 +1249,11 @@ fn run_ui_part13(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result
|
||||
"ui.livePaintGapOptions" => crate::dialogs::live_paint_gaps::open(app),
|
||||
"ui.perspectivePlane" => crate::dialogs::perspective_plane::open(app, p),
|
||||
crate::dialogs::check_spelling::COMMAND => crate::dialogs::check_spelling::open(app),
|
||||
"ui.findAndReplace" => {
|
||||
let empty = serde_json::Map::new();
|
||||
crate::dialogs::find_replace::open(app, &empty)
|
||||
}
|
||||
"ui.retype" => crate::panel_docking::reveal_panel(app, crate::panels::retype::ID),
|
||||
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
@@ -380,7 +380,7 @@ fn ui_enabled(app: &VectorcraftApp, id: &str) -> bool {
|
||||
id if id.starts_with(crate::dialogs::perspective_presets::SLOT) => {
|
||||
app.session.active().is_some() && crate::dialogs::perspective_presets::slot_preset(app, id).is_some()
|
||||
}
|
||||
"ui.perspectivePlane" => app.session.active().is_some(),
|
||||
"ui.perspectivePlane" | "ui.findAndReplace" | "ui.retype" => app.session.active().is_some(),
|
||||
"window.newWindow" => app.session.active().is_some(),
|
||||
// Tile and Cascade with two windows or more (documents, or views of one from New Window);
|
||||
// Float in Window for a current window under the tabs; Float All in Windows while a window
|
||||
|
||||
@@ -2170,4 +2170,6 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"",
|
||||
"{plane?: left|right|ground (default: the active plane)} open the plane's options, as double-clicking its plane widget does (dialog `perspectivePlane`: location (pt along the plane's normal), objects: none|move|copy): OK runs perspective.plane.move",
|
||||
),
|
||||
("ui.findAndReplace", "Find and Replace…", "", "{} open the Find and Replace dialog (Edit › Find and Replace…; dialog `findReplace`)"),
|
||||
("ui.retype", "Retype", "", "{} open the Retype panel (Window › Retype) or start Retype"),
|
||||
];
|
||||
|
||||
@@ -113,15 +113,20 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
crate::chrome::anchor_buttons(app, ui, anchors);
|
||||
}
|
||||
divider(ui);
|
||||
quick_actions_section(app, ui, first.as_deref(), n_sel);
|
||||
global_edit_row(app, ui);
|
||||
}
|
||||
|
||||
fn quick_actions_section(app: &mut VectorcraftApp, ui: &mut Ui, first: Option<&vectorcraft_doc::Node>, n_sel: usize) {
|
||||
section_header(ui, tl!("Quick Actions"));
|
||||
let is_group = matches!(first.as_ref().map(|n| &n.kind), Some(NodeKind::Group { .. }));
|
||||
let is_live = matches!(first.as_ref().map(|n| &n.kind), Some(NodeKind::Path { live: Some(l), .. }) if !matches!(**l, LiveShape::Path { .. }));
|
||||
let is_group = matches!(first.map(|n| &n.kind), Some(NodeKind::Group { .. }));
|
||||
let is_live = matches!(first.map(|n| &n.kind), Some(NodeKind::Path { live: Some(l), .. }) if !matches!(&**l, LiveShape::Path { .. }));
|
||||
// Blend Options for one selected blend, Merge Live Paint for a Live Paint group selected with
|
||||
// more to merge into it, as the Properties panel overview lists them
|
||||
// (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/properties-panel-overview.html>).
|
||||
// The overview names the Blend tool; the blending page has the button for a blend selected with
|
||||
// any tool (<https://helpx.adobe.com/illustrator/using/blending-objects.html>, #4817).
|
||||
let blend_options = n_sel == 1 && matches!(first.as_ref().map(|n| &n.kind), Some(NodeKind::Blend { .. }));
|
||||
let blend_options = n_sel == 1 && matches!(first.map(|n| &n.kind), Some(NodeKind::Blend { .. }));
|
||||
let merge_live_paint = n_sel > 1 && can_merge_live_paint(app);
|
||||
// Repeat Options for one selected repeat (radial, grid or mirror), or one object of its source
|
||||
// art in isolation mode: Object › Repeat › Options, the dialog of the repeat options pages
|
||||
@@ -156,6 +161,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
if multi_color(app, ui.ctx()) {
|
||||
actions.push((tl!("Recolor"), "ui.recolorDialog"));
|
||||
}
|
||||
let is_image = n_sel == 1 && matches!(first.map(|n| &n.kind), Some(NodeKind::Image(_)));
|
||||
if is_image {
|
||||
crate::panels::image_trace::trace_button(app, ui, ui.available_width());
|
||||
actions.push((tl!("Crop Image"), "ui.cropImage"));
|
||||
@@ -166,10 +172,26 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
// Object › Path's Offset Path and Simplify take paths: type alone could only fail, and offsets
|
||||
// live through the Appearance panel's Effect › Path › Offset Path (#2238).
|
||||
let type_only = app.session.active().is_some_and(|st| {
|
||||
let mut nodes = st.selection.objects.iter().filter_map(|id| st.doc.node(*id));
|
||||
nodes.all(|n| matches!(n.kind, NodeKind::Text(_)))
|
||||
let (has_type, type_only) = app.session.active().map_or((false, false), |st| {
|
||||
let mut any_type = false;
|
||||
let mut all_type = !st.selection.objects.is_empty();
|
||||
for id in &st.selection.objects {
|
||||
let is_text = st.doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Text(_)));
|
||||
any_type |= is_text;
|
||||
all_type &= is_text;
|
||||
}
|
||||
(any_type, all_type)
|
||||
});
|
||||
// Contextual Quick Actions for type selection (G12, Properties panel per context): Create
|
||||
// Outlines, Retype and Find and Replace…
|
||||
// (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/properties-panel-overview.html>).
|
||||
if has_type {
|
||||
actions.push((tl!("Create Outlines"), "type.createOutlines"));
|
||||
if crate::menus::enabled(app, "ui.retype") || crate::menus::enabled(app, "type.retype") {
|
||||
actions.push((tl!("Retype"), "ui.retype"));
|
||||
}
|
||||
actions.push((tl!("Find and Replace…"), "ui.findAndReplace"));
|
||||
}
|
||||
if !type_only {
|
||||
actions.push((tl!("Offset Path"), "object.path.offsetPath"));
|
||||
actions.push((tl!("Simplify"), "object.path.simplify"));
|
||||
@@ -189,7 +211,6 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
});
|
||||
}
|
||||
global_edit_row(app, ui);
|
||||
}
|
||||
|
||||
/// Whether Merge Live Paint can take the selection: a Live Paint group among the selected objects
|
||||
|
||||
@@ -1807,6 +1807,64 @@ fn offset_path_and_simplify_are_not_quick_actions_for_type_alone() {
|
||||
assert!(shows(&texts, "Offset Path") && shows(&texts, "Simplify"), "type and a path: {texts:?}");
|
||||
}
|
||||
|
||||
/// Contextual Quick Actions for type selection (G12): with text selected, Quick Actions shows
|
||||
/// Create Outlines, Retype and Find and Replace…; clicking Create Outlines converts the text
|
||||
/// to vector paths with one undo step. A non-text selection (plain path) displays Offset Path
|
||||
/// and Simplify without displaying Create Outlines.
|
||||
#[test]
|
||||
fn type_quick_actions_show_text_commands_and_create_outlines() {
|
||||
let mut app = new_app();
|
||||
let t = app.run("text.create", json!({"x": 50, "y": 200, "text": "Hello"})).unwrap()["id"].clone();
|
||||
let ctx = egui::Context::default();
|
||||
let texts = tall(&mut app, &ctx, vec![]);
|
||||
assert!(shows(&texts, "Create Outlines"), "text shows Create Outlines: {texts:?}");
|
||||
assert!(shows(&texts, "Retype"), "text shows Retype: {texts:?}");
|
||||
assert!(shows(&texts, "Find and Replace…"), "text shows Find and Replace…: {texts:?}");
|
||||
assert!(shows(&texts, "Arrange: Bring to Front") && shows(&texts, "Lock"), "standard object actions: {texts:?}");
|
||||
assert!(!shows(&texts, "Offset Path") && !shows(&texts, "Simplify"), "no offset path/simplify for type alone");
|
||||
|
||||
let undo0 = app.session.doc().unwrap().history.undo.len();
|
||||
press(&mut app, &ctx, text_at(&texts, "Create Outlines").center());
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo0 + 1, "one undo step");
|
||||
let sel = app.session.doc().unwrap().selection.objects.clone();
|
||||
assert!(!sel.is_empty(), "outlines are selected");
|
||||
for id in &sel {
|
||||
let node = app.session.doc().unwrap().doc.node(*id).unwrap();
|
||||
assert!(!matches!(node.kind, NodeKind::Text(_)), "converted from live text: {:?}", node.kind);
|
||||
}
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo0);
|
||||
let node = app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(t.as_u64().unwrap())).unwrap();
|
||||
assert!(matches!(node.kind, NodeKind::Text(_)), "undo restores live text");
|
||||
|
||||
// Non-text selection (plain path): continues to show Offset Path and Simplify without Create Outlines.
|
||||
let r = rect(&mut app, 20.0, 20.0, 40.0, 40.0);
|
||||
app.run("select.set", json!({"ids": [r]})).unwrap();
|
||||
let texts = tall(&mut app, &ctx, vec![]);
|
||||
assert!(shows(&texts, "Offset Path") && shows(&texts, "Simplify"), "path shows Offset Path and Simplify");
|
||||
assert!(!shows(&texts, "Create Outlines"), "path does not show Create Outlines");
|
||||
|
||||
// Find and Replace… quick action opens the Find and Replace dialog.
|
||||
app.run("select.set", json!({"ids": [t]})).unwrap();
|
||||
let texts = tall(&mut app, &ctx, vec![]);
|
||||
press(&mut app, &ctx, text_at(&texts, "Find and Replace…").center());
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("findReplace"), "opens findReplace dialog");
|
||||
|
||||
// Retype quick action reveals the Retype panel and leaves it open if already visible.
|
||||
app.ui.dialog = None;
|
||||
let retype_panel = crate::panels::retype::ID;
|
||||
assert!(!crate::panel_docking::visible(&app.ui, retype_panel), "Retype is initially hidden");
|
||||
|
||||
let texts = tall(&mut app, &ctx, vec![]);
|
||||
press(&mut app, &ctx, text_at(&texts, "Retype").center());
|
||||
assert!(crate::panel_docking::visible(&app.ui, retype_panel), "Retype panel is revealed when initially hidden");
|
||||
|
||||
// Clicking Retype again leaves the panel open rather than toggling it closed.
|
||||
let texts = tall(&mut app, &ctx, vec![]);
|
||||
press(&mut app, &ctx, text_at(&texts, "Retype").center());
|
||||
assert!(crate::panel_docking::visible(&app.ui, retype_panel), "Retype panel remains visible when already open");
|
||||
}
|
||||
|
||||
/// A dynamic symbol instance with appearance changes of its own has Reset in Quick Actions, which
|
||||
/// drops them (#4938); without changes there is no Reset.
|
||||
#[test]
|
||||
|
||||
@@ -98,7 +98,7 @@ fn highlight_made(ctx: &egui::Context, kind: Kind, names: Vec<String>) {
|
||||
|
||||
/// Duplicates the styles `names` (`charStyle.duplicate`, `paraStyle.duplicate`) in one undo step
|
||||
/// and highlights the copies.
|
||||
fn duplicate(app: &mut VectorcraftApp, ctx: &egui::Context, kind: Kind, names: &[String]) {
|
||||
fn duplicate(app: &mut VectorcraftApp, ctx: &egui::Context, kind: Kind, names: &[String]) -> Vec<String> {
|
||||
let p = kind.prefix();
|
||||
let made = if let [name] = names {
|
||||
app.run(&format!("{p}.duplicate"), json!({ "name": name })).map(|r| vec![r])
|
||||
@@ -108,7 +108,11 @@ fn duplicate(app: &mut VectorcraftApp, ctx: &egui::Context, kind: Kind, names: &
|
||||
app.run("command.batch", json!({ "label": label, "commands": commands })).map(|r| r["results"].as_array().cloned().unwrap_or_default())
|
||||
};
|
||||
if let Ok(made) = made {
|
||||
highlight_made(ctx, kind, made.iter().filter_map(|r| r["name"].as_str().map(str::to_string)).collect());
|
||||
let names: Vec<String> = made.iter().filter_map(|r| r["name"].as_str().map(str::to_string)).collect();
|
||||
highlight_made(ctx, kind, names.clone());
|
||||
names
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +258,48 @@ fn open_style_options(app: &mut VectorcraftApp, kind: Kind, name: &str) {
|
||||
app.run(command, json!({ "name": name })).ok();
|
||||
}
|
||||
|
||||
/// An item's right-click context menu in the Character Styles / Paragraph Styles panel.
|
||||
fn item_context_menu(app: &mut VectorcraftApp, ui: &mut Ui, kind: Kind, name: &str, normal: &str, sel: &mut Vec<String>, listed: &[&str]) {
|
||||
let p = kind.prefix();
|
||||
let is_normal = name == normal;
|
||||
let targets = dragged(sel, listed, name);
|
||||
let doomed: Vec<String> = targets.iter().filter(|s| *s != normal).cloned().collect();
|
||||
let has_text_target = text_style(app).is_some();
|
||||
|
||||
let options_label = crate::i18n::fmt(tl!("{kind} Style Options…"), &[("kind", kind.what_label())]);
|
||||
if menu_item(ui, &options_label, !is_normal, false) {
|
||||
open_style_options(app, kind, name);
|
||||
ui.close();
|
||||
}
|
||||
let duplicate_label = crate::i18n::fmt(tl!("Duplicate {kind} Style"), &[("kind", kind.what_label())]);
|
||||
if menu_item(ui, &duplicate_label, true, false) {
|
||||
let made = duplicate(app, ui.ctx(), kind, &targets);
|
||||
if !made.is_empty() {
|
||||
*sel = made;
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
let delete_label = crate::i18n::fmt(tl!("Delete {kind} Style"), &[("kind", kind.what_label())]);
|
||||
if menu_item(ui, &delete_label, !is_normal && !doomed.is_empty(), false) {
|
||||
if app.run(&format!("{p}.delete"), json!({ "names": doomed })).is_ok() {
|
||||
*sel = vec![];
|
||||
set_highlighted(ui.ctx(), kind, vec![]);
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
let redefine_label = crate::i18n::fmt(tl!("Redefine {kind} Style"), &[("kind", kind.what_label())]);
|
||||
if menu_item(ui, &redefine_label, has_text_target, false) {
|
||||
end_typing(app);
|
||||
app.run(&format!("{p}.redefine"), target(app, kind, json!({ "name": name }))).ok();
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, tl!("Clear Overrides"), has_text_target, false) {
|
||||
app.run(&format!("{p}.apply"), apply_target(app, kind, json!({ "name": name, "clearOverrides": true }))).ok();
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// The style list and its New and Delete buttons. Shift-click highlights every style from the
|
||||
/// last one clicked without Shift through this one, and Cmd/Ctrl-click adds or removes one; both
|
||||
/// leave the text as it is. Delete deletes every highlighted style but the Normal style.
|
||||
@@ -296,6 +342,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui, kind: Kind) {
|
||||
if scroll_to.as_deref() == Some(name.as_str()) {
|
||||
ui.scroll_to_rect(r, None);
|
||||
}
|
||||
if resp.secondary_clicked() && !sel.contains(name) {
|
||||
sel = vec![name.clone()];
|
||||
set_pstate(ui.ctx(), kind.anchor_key(), name.clone());
|
||||
set_highlighted(ui.ctx(), kind, sel.clone());
|
||||
}
|
||||
let (fill, outline) = row_look(is_cur, sel.contains(name), resp.hovered(), &t);
|
||||
if let Some(fill) = fill {
|
||||
ui.painter().rect_filled(r, 0.0, fill);
|
||||
@@ -308,6 +359,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui, kind: Kind) {
|
||||
let shown = super::label_or_name(name, *name == normal);
|
||||
let label = if overridden { format!("{shown}+") } else { shown.to_string() };
|
||||
ui.painter().text(r.left_center() + vec2(8.0, 0.0), egui::Align2::LEFT_CENTER, label, egui::FontId::proportional(12.5), t.text);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::ListItem, ui.is_enabled(), sel.contains(name), shown.to_string()));
|
||||
resp.context_menu(|ui| {
|
||||
item_context_menu(app, ui, kind, name, &normal, &mut sel, &listed);
|
||||
});
|
||||
if resp.clicked() {
|
||||
clicked = Some((name.clone(), ui.input(|i| i.modifiers)));
|
||||
}
|
||||
|
||||
@@ -1478,3 +1478,249 @@ fn character_style_unicode_boundary_capture_controls() {
|
||||
capture_from_ui(Some((2, 5)), redefine, footer, true);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_click_context_menu_in_character_styles_panel() {
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "Hello world", "size": 18})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
app.run("charStyle.new", json!({"name": "Body", "attrs": {"size": 18.0}})).unwrap();
|
||||
|
||||
let mut h = Harness::builder().with_size(vec2(280.0, 500.0)).with_accessibility_check(false).build_ui_state(
|
||||
|ui, app: &mut VectorcraftApp| {
|
||||
show(app, ui, Kind::Char);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(2);
|
||||
|
||||
// Initial state: Body is unselected in panel
|
||||
assert_eq!(pstate::<Option<String>>(&h.ctx, Kind::Char.key()), None, "Body is initially unselected");
|
||||
|
||||
// Right-click unselected row "Body"
|
||||
let node = h.get_by_label("Body");
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
// Right-clicking highlights it and opens context menu
|
||||
assert_eq!(pstate::<Option<String>>(&h.ctx, Kind::Char.key()).as_deref(), Some("Body"));
|
||||
|
||||
let opt = h.get_by_label(" Character Style Options…");
|
||||
let dup = h.get_by_label(" Duplicate Character Style");
|
||||
let del = h.get_by_label(" Delete Character Style");
|
||||
let redefine = h.get_by_label(" Redefine Character Style");
|
||||
let clear = h.get_by_label(" Clear Overrides");
|
||||
|
||||
assert!(!opt.accesskit_node().is_disabled());
|
||||
assert!(!dup.accesskit_node().is_disabled());
|
||||
assert!(!del.accesskit_node().is_disabled());
|
||||
assert!(!redefine.accesskit_node().is_disabled());
|
||||
assert!(!clear.accesskit_node().is_disabled());
|
||||
|
||||
// Clicking "Duplicate Character Style" creates a copy (e.g. "Body copy")
|
||||
dup.click();
|
||||
h.run_steps(2);
|
||||
|
||||
let all_styles = styles(h.state_mut(), Kind::Char);
|
||||
assert!(all_styles.iter().any(|s| s.0 == "Body copy"), "Body copy was created: {all_styles:?}");
|
||||
assert_eq!(pstate::<Option<String>>(&h.ctx, Kind::Char.key()).as_deref(), Some("Body copy"), "copy is highlighted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_click_context_menu_in_paragraph_styles_panel() {
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "Paragraph text", "size": 14})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
app.run("paraStyle.new", json!({"name": "Headline"})).unwrap();
|
||||
|
||||
let undo_len = app.session.doc().unwrap().history.undo.len();
|
||||
|
||||
let mut h = Harness::builder().with_size(vec2(280.0, 500.0)).with_accessibility_check(false).build_ui_state(
|
||||
|ui, app: &mut VectorcraftApp| {
|
||||
show(app, ui, Kind::Para);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(2);
|
||||
|
||||
// Initial state: Headline is unselected
|
||||
assert_eq!(pstate::<Option<String>>(&h.ctx, Kind::Para.key()), None, "Headline is initially unselected");
|
||||
|
||||
// Right-click unselected row "Headline"
|
||||
let node = h.get_by_label("Headline");
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
// Highlights it and opens context menu
|
||||
assert_eq!(pstate::<Option<String>>(&h.ctx, Kind::Para.key()).as_deref(), Some("Headline"));
|
||||
|
||||
let opt = h.get_by_label(" Paragraph Style Options…");
|
||||
let dup = h.get_by_label(" Duplicate Paragraph Style");
|
||||
let del = h.get_by_label(" Delete Paragraph Style");
|
||||
let redefine = h.get_by_label(" Redefine Paragraph Style");
|
||||
let clear = h.get_by_label(" Clear Overrides");
|
||||
|
||||
assert!(!opt.accesskit_node().is_disabled());
|
||||
assert!(!dup.accesskit_node().is_disabled());
|
||||
assert!(!del.accesskit_node().is_disabled());
|
||||
assert!(!redefine.accesskit_node().is_disabled());
|
||||
assert!(!clear.accesskit_node().is_disabled());
|
||||
|
||||
// Clicking "Delete Paragraph Style" deletes the style with undo support
|
||||
del.click();
|
||||
h.run_steps(2);
|
||||
|
||||
let all_styles = styles(h.state_mut(), Kind::Para);
|
||||
assert!(!all_styles.iter().any(|s| s.0 == "Headline"), "Headline deleted: {all_styles:?}");
|
||||
assert_eq!(pstate::<Option<String>>(&h.ctx, Kind::Para.key()), None, "selection cleared after delete");
|
||||
assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo_len + 1, "delete recorded one undo step");
|
||||
|
||||
// Test undo
|
||||
h.state_mut().run("edit.undo", json!({})).unwrap();
|
||||
let restored = styles(h.state_mut(), Kind::Para);
|
||||
assert!(restored.iter().any(|s| s.0 == "Headline"), "Headline restored by undo: {restored:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_click_context_menu_normal_style_disables_options_and_delete() {
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
|
||||
let mut h = Harness::builder().with_size(vec2(280.0, 500.0)).with_accessibility_check(false).build_ui_state(
|
||||
|ui, app: &mut VectorcraftApp| {
|
||||
show(app, ui, Kind::Char);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(2);
|
||||
|
||||
// Right-click Normal Character Style row
|
||||
let node = h.get_by_label("[Normal Character Style]");
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
let opt = h.get_by_label(" Character Style Options…");
|
||||
let dup = h.get_by_label(" Duplicate Character Style");
|
||||
let del = h.get_by_label(" Delete Character Style");
|
||||
|
||||
assert!(opt.accesskit_node().is_disabled(), "Options disabled for Normal style");
|
||||
assert!(!dup.accesskit_node().is_disabled(), "Duplicate enabled for Normal style");
|
||||
assert!(del.accesskit_node().is_disabled(), "Delete disabled for Normal style");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_click_context_menu_preserves_multiselection() {
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
app.run("charStyle.new", json!({"name": "Style A"})).unwrap();
|
||||
app.run("charStyle.new", json!({"name": "Style B"})).unwrap();
|
||||
|
||||
let mut h = Harness::builder().with_size(vec2(280.0, 500.0)).with_accessibility_check(false).build_ui_state(
|
||||
|ui, app: &mut VectorcraftApp| {
|
||||
show(app, ui, Kind::Char);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(2);
|
||||
|
||||
// Highlight both styles in pstate
|
||||
set_highlighted(&h.ctx, Kind::Char, vec!["Style A".into(), "Style B".into()]);
|
||||
h.run_steps(2);
|
||||
|
||||
// Right-click Style B (which is part of the multi-selection)
|
||||
let node = h.get_by_label("Style B");
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
// Multiselection is preserved
|
||||
let sel = highlighted(h.state(), &h.ctx, Kind::Char, &["[Normal Character Style]", "Style A", "Style B"]);
|
||||
assert_eq!(sel, vec!["Style A".to_string(), "Style B".to_string()], "multi-selection preserved on right-click");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_click_context_menu_clear_overrides_requires_text_target() {
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
app.run("charStyle.new", json!({"name": "Style 1"})).unwrap();
|
||||
|
||||
// Select a non-text shape: rectangle
|
||||
let rect_id = app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 60, "height": 60})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [rect_id]})).unwrap();
|
||||
|
||||
let mut h = Harness::builder().with_size(vec2(280.0, 500.0)).with_accessibility_check(false).build_ui_state(
|
||||
|ui, app: &mut VectorcraftApp| {
|
||||
show(app, ui, Kind::Char);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(2);
|
||||
|
||||
// Right-click Style 1
|
||||
let node = h.get_by_label("Style 1");
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
let clear_overrides = h.get_by_label(" Clear Overrides");
|
||||
let redefine = h.get_by_label(" Redefine Character Style");
|
||||
assert!(clear_overrides.accesskit_node().is_disabled(), "Clear Overrides disabled when only a rectangle is selected");
|
||||
assert!(redefine.accesskit_node().is_disabled(), "Redefine disabled when only a rectangle is selected");
|
||||
|
||||
// Close menu
|
||||
h.event(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
// Now select a text object
|
||||
let text_id = h.state_mut().run("text.create", json!({"x": 10, "y": 10, "text": "Hello"})).unwrap()["id"].as_u64().unwrap();
|
||||
h.state_mut().run("select.set", json!({"ids": [text_id]})).unwrap();
|
||||
h.run_steps(2);
|
||||
|
||||
// Right-click Style 1 again
|
||||
let node = h.get_by_label("Style 1");
|
||||
let pos = node.rect().center();
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: true, modifiers: Default::default() });
|
||||
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Secondary, pressed: false, modifiers: Default::default() });
|
||||
h.run_steps(2);
|
||||
|
||||
let clear_overrides = h.get_by_label(" Clear Overrides");
|
||||
let redefine = h.get_by_label(" Redefine Character Style");
|
||||
assert!(!clear_overrides.accesskit_node().is_disabled(), "Clear Overrides enabled when text is selected");
|
||||
assert!(!redefine.accesskit_node().is_disabled(), "Redefine enabled when text is selected");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user