Undo groups: library styles and field scrubs close only the group they open

Using a library's character or paragraph style, and scrubbing a
numeric field, closed their undo step with Session::end_undo_group,
which closes the open undo group of every document. An undo group open
in another document, such as one begun with edit.undoGroup.begin for
an MCP command_batch with atomic, was closed too, and that document's
next edits became undo steps of their own. When the style failed to
apply, or Escape ended the scrub, the other document's group was
canceled as well and the edits made in it were undone. Inside an undo
group already open in the same document, a scrub closed that group,
Escape undid the edits made in it before the drag, and a style that
failed to apply left the style it had added.

Session::begin_undo_scope and end_undo_scope make the edits in between
one undo step of the active document: the scope opens an undo group
there, or joins the one already open. Ending a scope closes only the
group it opened, in its own document, even when another document
became active in the meantime, and a canceled scope undoes only its
own edits, also inside a group that was already open. library.use and
the scrub use the scope, so Escape inside an open group also takes
back a scrub of the Transform panel's Shear field. edit.undoGroup.end
still closes the open group of every document.
This commit is contained in:
dotCooCoo
2026-10-21 16:46:19 +07:00
committed by bflatastic
parent 5846b00da3
commit ae41ddb9a5
7 changed files with 311 additions and 14 deletions
+5 -8
View File
@@ -932,16 +932,13 @@ fn use_item(s: &mut Session, p: &Value) -> Result<Value> {
}
}
/// Run `f`'s commands as one undo step (undone together when it fails), unless an undo group is
/// already open (its own step then holds them).
/// Run `f`'s commands as one undo step, or as part of the step of an undo group open in the active
/// document, and undo them together when it fails ([`Session::begin_undo_scope`]).
fn in_one_step<T>(s: &mut Session, f: impl FnOnce(&mut Session) -> Result<T>) -> Result<T> {
let open = s.active().is_some_and(|st| st.undo_group.is_some());
if !open {
s.begin_undo_group();
}
let scope = s.begin_undo_scope();
let r = f(s);
if !open {
s.end_undo_group(r.is_err());
if let Some(scope) = scope {
s.end_undo_scope(scope, r.is_err());
}
r
}