Keep unchanged Brush Options out of document history

This commit is contained in:
dotCooCoo
2026-11-27 08:25:38 -08:00
parent 37fc94d291
commit c71a86d8ad
6 changed files with 119 additions and 6 deletions
+1 -1
View File
@@ -1114,7 +1114,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.brushOptions",
"Brush Options…",
"",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options only when its name or options changed; unchanged approval preserves the brush and adds no Undo",
),
(
"ui.brushObjectOptions",
+13 -2
View File
@@ -3,8 +3,9 @@
//! Tilt, Bearing or Rotation with its Variation, over live previews of the nib and of a stroke
//! (light, heavy, light pressure). Bristle Brush Options: Name (a new bristle brush name that is too
//! long is refused at OK), Shape and the bristle sliders. Scatter, Art and Pattern Brush Options: see
//! [`super::brush_art_options`]. OK runs `brush.options` (strokes painted with the brush update);
//! a name another brush has, or a new bristle brush name that is too long, keeps the dialog open.
//! [`super::brush_art_options`]. A changed OK runs `brush.options` (strokes painted with the brush update);
//! accepting unchanged settings closes without an Undo step.
//! A name another brush has, or a new bristle brush name that is too long, keeps the dialog open.
//!
//! Fields: `__brush` (the brush's name), `__type` (`calligraphic` | `bristle` | `scatter` | `art` |
//! `pattern`), `name`.
@@ -183,6 +184,7 @@ fn open_dialog(app: &mut VectorcraftApp, f: &Map<String, Value>, object_keys: Op
initial.set(OPENED, FieldValue::Json(Value::Object(opened)));
initial.set(KEYS, FieldValue::Json(json!(keys)));
}
let unchanged = (!object && !flag(&initial, CREATE)).then(|| (string(&initial, "name"), string(&initial, "__brush"), params(&initial)));
// The canvas of the current window: the Key Color dropper samples there while the dialog is open.
let canvas = crate::doc_windows::current(app).map(crate::canvas::canvas_id);
let dialog = HostedParamDialog::new(&ctx, KIND, initial, move |fields| {
@@ -202,6 +204,15 @@ fn open_dialog(app: &mut VectorcraftApp, f: &Map<String, Value>, object_keys: Op
None if !object => return Err(tl!("Return to the original drawing to edit its brush").into()),
_ => {}
}
if let Some((opened_name, brush, opened_params)) = &unchanged {
let name = string(&result.fields, "name");
// The command ignores an empty name and trims a supplied rename.
let same_name = name == *opened_name || name.trim().is_empty() || name.trim() == brush;
if same_name && params(&result.fields) == *opened_params {
// A deleted brush still reports its normal error instead of accepting a stale dialog.
return app.run("brush.get", json!({"name": brush})).map(|_| ());
}
}
ok(app, result)
})
.ok_or("no window")?,
@@ -9,6 +9,102 @@ fn app() -> VectorcraftApp {
app
}
#[test]
fn unchanged_normal_brush_approval_keeps_the_document_and_undo_history_exact() {
use crate::tests::panel_harness::Panel;
for name in ["6 pt. Flat", "Bristle Round", "Confetti", "Arrow", "Diamonds"] {
let mut app = app();
let params = if name == "Arrow" { json!({"width": 100.25}) } else { json!({}) };
// Establish a saved library before testing a normal approval of an existing brush.
app.run("brush.options", json!({"name": name, "params": params})).unwrap();
let brush = app.run("brush.get", json!({"name": name})).unwrap();
let document = app.session.active().unwrap().doc.clone();
let revision = app.session.active().unwrap().revision;
let undo = app.session.active().unwrap().history.undo.len();
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
panel.room(vec2(1200.0, 1200.0));
panel.app().run("ui.brushOptions", json!({"name": name})).unwrap();
panel.frame();
panel.click("OK");
panel.frame();
panel.frame();
assert!(!is_open(&panel.app()), "the unchanged {name} dialog closes normally");
assert_eq!(panel.app().run("brush.get", json!({"name": name})).unwrap(), brush);
let app = panel.app();
let st = app.session.active().unwrap();
assert_eq!(st.doc, document, "unchanged {name} approval preserves the entire stored library");
assert_eq!(st.revision, revision);
assert_eq!(st.history.undo.len(), undo, "unchanged {name} approval adds no Undo step");
}
}
#[test]
fn brush_automation_approval_skips_noop_but_saves_changed_options_in_one_step() {
let mut app = app();
app.run("brush.options", json!({"name": "Arrow", "params": {"width": 100.25}})).unwrap();
let original = app.session.active().unwrap().doc.clone();
let revision = app.session.active().unwrap().revision;
let undo = app.session.active().unwrap().history.undo.len();
open(&mut app, "Arrow");
confirm(&mut app).unwrap();
assert_eq!(app.session.active().unwrap().doc, original);
assert_eq!(app.session.active().unwrap().revision, revision);
assert_eq!(app.session.active().unwrap().history.undo.len(), undo);
for name in [" Arrow ", ""] {
open(&mut app, "Arrow");
set(&mut app, json!({"name": name}));
confirm(&mut app).unwrap();
assert_eq!(app.session.active().unwrap().doc, original, "a command-equivalent name does not rewrite the brush");
assert_eq!(app.session.active().unwrap().history.undo.len(), undo);
}
open(&mut app, "Arrow");
set(&mut app, json!({"width": 110.25}));
confirm(&mut app).unwrap();
assert_eq!(app.run("brush.get", json!({"name": "Arrow"})).unwrap()["width"], json!(110.25));
assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1);
app.run("edit.undo", json!({})).unwrap();
assert_eq!(app.session.active().unwrap().doc, original);
}
#[test]
fn normal_brush_rename_still_saves_and_a_deleted_brush_still_refuses_approval() {
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use egui::{Key, Modifiers};
let mut app = app();
app.run("brush.options", json!({"name": "Arrow", "params": {}})).unwrap();
let original = app.session.active().unwrap().doc.clone();
let undo = app.session.active().unwrap().history.undo.len();
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
panel.room(vec2(1200.0, 1200.0));
panel.app().run("ui.brushOptions", json!({"name": "Arrow"})).unwrap();
panel.frame();
panel.click_role("Name", Role::TEXT_INPUT);
panel.key(Key::A, Modifiers::COMMAND);
panel.type_text("Renamed Arrow");
panel.key(Key::Tab, Modifiers::NONE);
panel.click("OK");
panel.frame();
panel.frame();
assert!(!is_open(&panel.app()));
assert!(panel.app().run("brush.get", json!({"name": "Renamed Arrow"})).is_ok());
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo + 1);
panel.app().run("edit.undo", json!({})).unwrap();
assert_eq!(panel.app().session.active().unwrap().doc, original);
open(&mut panel.app(), "Arrow");
panel.app().run("brush.delete", json!({"name": "Arrow"})).unwrap();
let deleted = panel.app().session.active().unwrap().doc.clone();
let undo = panel.app().session.active().unwrap().history.undo.len();
assert!(confirm(&mut panel.app()).unwrap_err().contains("no brush named"));
assert!(is_open(&panel.app()), "the stale unchanged dialog reports its normal error");
assert_eq!(panel.app().session.active().unwrap().doc, deleted);
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo);
cancel(&mut panel.app());
}
fn ctx(app: &VectorcraftApp) -> egui::Context {
app.ui_ctx.clone().expect("the test app has a context")
}
+1 -1
View File
@@ -1115,7 +1115,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.brushOptions",
"Brush Options…",
"",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options",
"{name?} (default: the selected path's brush, else the current brush) open its Brush Options, what double-clicking a brush in the Brushes panel opens (dialog `brushOptions`): Calligraphic (fields name, angle −180..180, roundness 0..100, size 0..1296 pt, angleMode/roundnessMode/sizeMode: fixed|random|pressure, angleVariation/roundnessVariation/sizeVariation), Bristle (fields name, shape, size, length, density, thickness, opacity, stiffness), Scatter (fields sizeMin/sizeMax/sizeMode, spacingMin/spacingMax/spacingMode, scatterMin/scatterMax/scatterMode, rotationMin/rotationMax/rotationMode with modes fixed|random|pressure, rotationRelativeTo: page|path, hueJitter 0..180°), Art (fields width %, scaleMode: proportional|stretch|betweenGuides, guideStart/guideEnd % of the art length, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flipAlong, flipAcross) or Pattern (fields scale %, spacing %, fit: stretch|addSpace|approximate, flipAlong, flipAcross); Scatter, Art and Pattern also colorization: none|tints|tintsAndShades|hueShift, keyColor, and tips: true opens Colorization Tips (what each method does, beside a sample of the brush painted with it), as the Tips button beside Method does; OK runs brush.options only when its name or options changed; unchanged approval preserves the brush and adds no Undo",
),
(
"ui.brushObjectOptions",
+6 -1
View File
@@ -1,6 +1,6 @@
# VectorCraft MCP server
> **Last updated:** 2026-11-18 · **Change:** Production Preflight command and report coverage; previously: `text.setFormat {composer}` and paragraph styles also take `standardSingleLine` and `standardEveryLine` (#4935); existing values and responses unchanged. Previously: Pencil ignores Smart Guides and Snap to Point and shows no Smart Guides, #7252; no response-shape change. Previously: Pencil continuation, straight-line and closing cursors; scores and estimates unchanged; no response-shape change. Previously: Snap to Point with Smart Guides off draws no Smart Guides labels or lines, #7250; no response-shape change. Previously: Envelopes: a top object's side whose pieces are all one curve split at anchors follows that curve's parameter (#7097); existing response shapes retained.
> **Last updated:** 2026-11-27 · **Change:** Brush Options: unchanged approval preserves the brush and adds no Undo; changed options save in one step; previously: Production Preflight command and report coverage; previously: `text.setFormat {composer}` and paragraph styles also take `standardSingleLine` and `standardEveryLine` (#4935); existing values and responses unchanged. Previously: Pencil ignores Smart Guides and Snap to Point and shows no Smart Guides, #7252; no response-shape change. Previously: Pencil continuation, straight-line and closing cursors; scores and estimates unchanged; no response-shape change. Previously: Snap to Point with Smart Guides off draws no Smart Guides labels or lines, #7250; no response-shape change. Previously: Envelopes: a top object's side whose pieces are all one curve split at anchors follows that curve's parameter (#7097); existing response shapes retained.
>
> Tech Circuit update (2026-11-14): three original procedural brushes; ten built-in brush libraries (G5).
@@ -5446,6 +5446,10 @@ already walks Image Trace. Short agent entry points:
for new art become no fill and a 0.5 pt black stroke; with New Art Has Basic Appearance off, new art then takes the
selection's appearance, as after any command.
For an existing brush, approving Brush Options without changing its trimmed name or options closes the dialog
without rewriting the brush, changing the document revision or adding Undo. A changed name or option is saved in
one step. A brush deleted while its dialog is open still gives an error on approval.
`brush.selectionArt {ids?|id?}` (a query) replies `{art}`: the object that `brush.new` given the same `ids` or `id`,
or the same selection, takes as a new scatter or art brush's art and as a new pattern brush's side tile. Several
objects become one group, and `art` is `null` when nothing is selected or `ids` name no object. In the app, the
@@ -17024,6 +17028,7 @@ the error text. The interactive fallback applies only to ordinary File > Save, n
| Date | Change |
|---|---|
| 2026-11-27 | Brush Options: untouched approval preserves the brush, document revision and Undo; changed settings save in one step. Native UI and automation covered. Scores and estimates unchanged. |
| 2026-11-18 | Production Preflight: output and artboard scope, four check summaries, clickable canvas ids, effective PPI and explicit unchecked resolution coverage. |
| 2026-11-14 | Built-in Tech Circuit brush library (id `tech-circuit`): Circuit Trace, Bus Lines and Terminal Nodes; ten built-in libraries. |
| 2026-11-13 | The Pencil ignores Smart Guides and Snap to Point and shows no Smart Guides; Snap to Grid and Snap to Pixel still move its ends (#7252). |
+2 -1
View File
File diff suppressed because one or more lines are too long