mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 00:40:57 -06:00
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:
@@ -80,23 +80,28 @@ pub(crate) fn phase(ctx: &Context) -> Phase {
|
||||
}
|
||||
}
|
||||
|
||||
/// Before the panels draw: while a field is scrubbed, the edits its values make are one undo step.
|
||||
/// (The drag's first frame applies nothing, so the group is open before its first value.)
|
||||
/// Before the panels draw: while a field is scrubbed, the edits its values make are one undo step,
|
||||
/// or part of the step of an undo group open in the active document
|
||||
/// ([`vectorcraft_engine::Session::begin_undo_scope`]). (The drag's first frame applies nothing, so
|
||||
/// the step begins before its first value.)
|
||||
pub(crate) fn begin_frame(app: &mut VectorcraftApp, ctx: &Context) {
|
||||
if !app.scrub_group && matches!(phase(ctx), Phase::Dragging | Phase::Released) {
|
||||
app.session.begin_undo_group();
|
||||
app.scrub_scope = app.session.begin_undo_scope();
|
||||
app.scrub_group = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// After the panels: a finished drag closes its undo group; Escape undoes it.
|
||||
/// After the panels: a finished drag ends its undo step in the document it began in, even when
|
||||
/// another document is active by then; Escape undoes the drag's edits.
|
||||
pub(crate) fn end_frame(app: &mut VectorcraftApp, ctx: &Context) {
|
||||
let phase = phase(ctx);
|
||||
if !app.scrub_group || phase == Phase::Dragging {
|
||||
return;
|
||||
}
|
||||
app.scrub_group = false;
|
||||
app.session.end_undo_group(phase == Phase::Cancelled);
|
||||
if let Some(scope) = app.scrub_scope.take() {
|
||||
app.session.end_undo_scope(scope, phase == Phase::Cancelled);
|
||||
}
|
||||
app.sync_views();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user