Scripts: duplicate, selection and wrapper fixes for the object model

- duplicate() runs Edit > Duplicate, the place and the selection
  restore under one savepoint, so a refused place leaves the documents,
  the selection and the undo history as they were. It reads the copy's
  id from the command's own result, so ids above 2^53 return the copy.
  A path inside a compound path throws an error instead of copying the
  whole compound path.
- An edit restores a mixed selection (direct-selected anchors and whole
  objects) in its original order with one select.anchorsMany.
- Assigning the selection clears a Layers panel target.
- A call on an inactive document switches back even when the selection
  restore fails.
- documents.add with a grid by column passes the row count to file.new,
  which takes a new artboardLayout.rows key: 5 artboards in 4 rows give
  columns of 4 and 1. A preset keeps the rows until columns without
  rows, or another layout, is given, and New Document drops them when
  Columns or the layout changes.
- A held page item stays the same object when its class changes in the
  same family (a placed image that is embedded becomes a RasterItem).
- A waiting class member's answer is read as a class instance, and a
  class constructor called with new cannot wait.

Docs: docs/mcp.md (DocumentPreset, duplicate, file.new rows), docs/gaps.md
(G6).
This commit is contained in:
dotCooCoo committed 2026-11-21 08:43:10 -08:00
1 parent f2d3b09fe6
commit f70d2ee7e6
14 files changed
+408 -104

No files matched your search

+8 -2
View File
@@ -1237,7 +1237,8 @@ fn note_ids(s: &mut Session) {
fn step(s: &mut Session, host: &Host, id: &str, params: &Value) -> Result<(Value, u64, u64, Option<Savepoint>)> {
raise_ids(s);
let mutating = waits_for_tool_edit(id);
let save = mutating.then(|| Savepoint::take(s, id));
// Inside an object-model call's own savepoint ([`dom`]), that savepoint puts a failure back.
let save = (mutating && !host.dom.saving()).then(|| Savepoint::take(s, id));
let before: Vec<(u64, Arc<crate::Document>, u64)> =
if mutating { s.docs.iter().map(|d| (d.uid, d.doc.clone(), d.doc.peek_next_id())).collect() } else { Vec::new() };
crate::file_access::start_recording_writes();
@@ -1303,6 +1304,11 @@ fn vc_run(host: &Rc<Host>, args: Vec<Data>) -> std::result::Result<Data, HostErr
/// transaction, its growth is counted, and a command that fails, or whose result cannot cross to
/// the script, is put back. → its result.
fn command(host: &Host, id: &str, params: &Value) -> std::result::Result<Data, HostError> {
command_value(host, id, params).map(|(data, _)| data)
}
/// [`command`], with the command's result as it gave it as well as the script's copy of it.
fn command_value(host: &Host, id: &str, params: &Value) -> std::result::Result<(Data, Value), HostError> {
let id = id.to_string();
let params = params.clone();
let session = host.session.clone();
@@ -1340,7 +1346,7 @@ fn command(host: &Host, id: &str, params: &Value) -> std::result::Result<Data, H
return Err(HostError::Abort(HISTORY_LOST.to_string()));
}
}
crossed
crossed.map(|data| (data, value))
}
/// A bounded snapshot of the active document, or `null` with none open. A snapshot past the limits