mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 18:32:23 +00:00
Properties panel: add contextual Quick Actions for text (Create Outlines, Retype, Find and Replace) (#8778)
* Properties panel: add contextual Quick Actions for text (Create Outlines, Retype, Find and Replace) * Properties panel: address review comments on Retype reveal idempotency, test assertions and parity docs
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]
|
||||
|
||||
+5
-1
File diff suppressed because one or more lines are too long
+4
-3
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user