Scripts: objectOnly paint, empty closed paths and style applyTo keep their rules

- An objectOnly paint during an open interaction also restores the paint
  waiting for the commit, so it no longer reaches Recent Colors.
- setEntirePath([]) on a closed path keeps an empty closed subpath, so
  the path stays closed.
- A character or paragraph style's applyTo throws Cannot edit, with
  nothing changed, on a hidden or locked text frame or one on a locked
  artboard, as other text edits do.
This commit is contained in:
dotCooCoo committed 2026-11-30 12:01:00 -08:00
1 parent b893fce701
commit 39a0fd6923
7 files changed
+27 -6

No files matched your search

+2 -2
View File
@@ -955,9 +955,9 @@ pub(crate) fn object_only(s: &mut Session, p: &Value, cmd: &str, run: impl FnOnc
if (!names(p, "ids") && !names(p, "id")) || asks_defaults_only(p) {
return Err(bad(cmd, "objectOnly needs ids or id and cannot be combined with defaultsOnly"));
}
let kept = (s.paint.clone(), s.fill_active, s.last_solid, s.last_gradient.clone(), s.recent_colors.clone());
let kept = (s.paint.clone(), s.fill_active, s.last_solid, s.last_gradient.clone(), s.recent_colors.clone(), s.pending_paint.clone());
let result = run(s);
(s.paint, s.fill_active, s.last_solid, s.last_gradient, s.recent_colors) = kept;
(s.paint, s.fill_active, s.last_solid, s.last_gradient, s.recent_colors, s.pending_paint) = kept;
if result.is_ok() {
s.note_defaults_only();
}
+1 -1
View File
@@ -857,7 +857,7 @@ fn path_set_entire(h: &super::Host, a: &[Data]) -> Answer {
let c = h.dom.coords.get();
let anchors: Vec<Anchor> =
script.iter().map(|p| in_canvas(f.to_document(c, *p), "each point").map(Anchor::corner)).collect::<std::result::Result<_, _>>()?;
let subs = if anchors.is_empty() { Vec::new() } else { vec![SubPath::new(anchors, closed)] };
let subs = if anchors.is_empty() && !closed { Vec::new() } else { vec![SubPath::new(anchors, closed)] };
write_path(h, item, subs)?;
cut_points(h, item);
Ok(Data::Undefined)
+3 -1
View File
@@ -342,7 +342,8 @@ fn target_span(h: &Host, d: &Data) -> std::result::Result<Span, HostError> {
span_of(h, d, &TEXT)
}
/// `applyTo(textItem, clearingOverrides?)`.
/// `applyTo(textItem, clearingOverrides?)`. Throws `Cannot edit`, with nothing changed, when the
/// text frame is protected as for any other text edit.
fn style_apply_to(h: &Host, a: &[Data]) -> Answer {
let style = this_style(h, a)?;
let target = target_span(h, arg(a, 1))?;
@@ -355,6 +356,7 @@ fn style_apply_to(h: &Host, a: &[Data]) -> Answer {
return Err(HostError::Error("the text is in another document than the style".into()));
}
let (index, s, e, _) = resolve(h, target)?;
super::refuse_protected(h, target.item, "TextFrame")?;
h.charge_call(16 + (e - s) as u64)?;
let (start, end) = if style.para {
let (_, ba, bb) = para_range(&index, s, e);
+15
View File
@@ -70,6 +70,21 @@ fn balance_previews_and_commits_one_step() {
assert_eq!(fill_of(&s, a).to_hex(), "#808080");
}
/// An `objectOnly` paint during an open interaction keeps the remembered colors: the paint it would
/// leave waiting for the commit is not added to Recent Colors when the interaction commits.
#[test]
fn object_only_paint_in_an_interaction_keeps_recent_colors() {
let mut s = session();
let a = rect(&mut s, json!("#808080"));
s.recent_colors.clear();
let recent = (s.recent_colors.clone(), s.last_solid);
s.begin_interaction("Adjust Colors").unwrap();
s.execute("paint.setFill", &json!({"ids": [a.0], "color": "#ff0000", "objectOnly": true})).unwrap();
assert_eq!(fill_of(&s, a).to_hex(), "#ff0000");
s.commit_interaction().unwrap();
assert_eq!((s.recent_colors.clone(), s.last_solid), recent, "the recent colors are as they were");
}
/// Saturate needs its intensity: a call without one, or with one that is not a number, is an error
/// that changes nothing and records no undo step. A number outside −100..100 counts as its nearest end.
#[test]
+1 -1
View File
@@ -124,7 +124,7 @@ fn mixed_anchor_and_segment_picks_keep_independent_anchors() {
#[test]
fn an_empty_path_keeps_closed_before_points_are_added() {
for add in ["p.pathPoints.add(); p.pathPoints.add();", "p.setEntirePath([[0, 0], [10, 0], [10, 10]]);"] {
for add in ["p.pathPoints.add(); p.pathPoints.add();", "p.setEntirePath([[0, 0], [10, 0], [10, 10]]);", "p.setEntirePath([]);"] {
let (mut s, _, _) = doc();
let start = s.journal.len();
let out = log(
+3
View File
@@ -348,6 +348,9 @@ fn hidden_or_locked_type_is_not_edited() {
"r.contents = 'xyz';",
"r.characters.add('!');",
"r.justification = Justification.CENTER;",
"var b = app.activeDocument.characterStyles.add('Big'); b.characterAttributes.size = 30; b.applyTo(r);",
"var b = app.activeDocument.characterStyles.add('Big'); b.characterAttributes.size = 30; b.applyTo(t);",
"var c = app.activeDocument.paragraphStyles.add('C'); c.paragraphAttributes.justification = Justification.CENTER; c.applyTo(r);",
] {
// Each case starts from a fresh frame, so the hidden cases test a frame that is only hidden.
let (mut s, id) = doc_with("abc");
+2 -1
View File
@@ -3292,7 +3292,8 @@ through `$`:
style's old value. `applyTo` takes a text range, a text frame or its characters, words or paragraphs, in the
style's document; a character style on an empty range inside text changes nothing, on empty text it styles the
text typed or set later, and a paragraph style styles every paragraph the text touches. `clearingOverrides` left
out is false. A range lists each style once, in the order
out is false. `applyTo` on a frame that is hidden or locked, in a hidden or locked layer or group, or on a locked
artboard throws `Cannot edit` with nothing changed. A range lists each style once, in the order
its text first uses it, the Normal style standing for text in no other style, and its lists cannot add or remove
styles. The Normal styles cannot be renamed or removed. A style object keeps naming its style after a rename made
through `name`; after the style is removed, renamed another way or its document closed or reverted, it throws