Skip to main content

Module history

Module history 

Source
Expand description

Undo histories, as the interface sees them (ADR 0014): the pure parts of the History contract.

Experimental: may change in any release (docs/stability.md).
  • A scope (ScopeId, described by ScopeInfo) is one history: a document’s edit, a collection’s marks, the application’s values, the settings window. Steps never cross scopes.
  • A step says what it is, not how to undo it (StepInfo): its id, scope, Label, origin, group, the place of the context stack it was made in, its time and whether it is still in progress. The inverse stays with the owner.
  • A scope’s steps are a Line: what an undo walks back (oldest first) and what a redo makes again (the next one last), with the scope’s revision. Redo is linear: a new step drops the redo list.
  • Merging (merges): repeats on one target (held arrows, wheel notches, a colour picker’s frames) carry the same merge key and are one step while they come less than MERGE_WINDOW apart, from the same origin, the focus unchanged.
  • Routing (newest): Ctrl+Z, outside a text field and a focused local scope, undoes the newest step among the scopes active in the window, unless the application routes by focus (the API crate’s history::Routing).
  • A jump (plan_jump) is a run of undos or redos to a step.
  • Beyond them, as an owner supports them (Features): a Snapshot (a named state pinned in a scope), a Preview of a point (At) the pointer is on, the steps a new step dropped from the redo list (Replaced), and one step undone out of order, unless a later step shares a target (may_undo_out_of_order).
use egui_pop_model::commands::Origin;
use egui_pop_model::history::{Label, Line, MergeMark, ScopeId, StepInfo, merges, plan_jump};

let a = MergeMark::new("view/zoom", Origin::User, 10.0);
assert!(merges(&a, &MergeMark::new("view/zoom", Origin::User, 10.4)));
assert!(!merges(&a, &MergeMark::new("view/zoom", Origin::User, 11.5)));

let step = |id| StepInfo::new(id, ScopeId::from_static("app"), Label::text("Zoom"), Origin::User);
let line = Line { undo: vec![step(1), step(2)], redo: vec![step(3)], rev: 4 };
let jump = plan_jump(&line, 3).unwrap();
assert_eq!((jump.redo, jump.count), (true, 1));

Re-exports§

pub use crate::ids::ScopeId;

Structs§

Features
What an owner supports beyond undo, redo and jump, per scope; the history panel offers only these.
Jump
A jump, as undos or redos.
Label
What a step is called: a message id and its arguments, rendered in the interface’s language when shown, with its English text for an interface that does not know the message (“Exposure +0.30 EV”).
Line
A scope’s steps.
MergeMark
What a step carries to be merged with the next: its merge key (the target path, or the component’s own key), origin and time.
Preview
What the owner answers a hover on the history panel: it may show the state there itself (shown: in its own views, the image as it was), and say what differs from now, which the panel shows beside the row. Nothing is committed: the hover ending cancels it.
PreviewChange
One thing a preview says differs.
Refusal
A refusal, with its reason as the interface shows it.
Replaced
A step a new step dropped from the redo list, kept by an owner whose history keeps every state (ADR 0014): the history panel shows it as a “replaced” row behind a toggle, and a jump reaches it.
Request
An undo, a redo or a jump asked of a scope.
ScopeInfo
A history, described.
Snapshot
A named state pinned in a scope (ADR 0014): taken by the user or an agent, never dropped by the cap, restored as a new step.
StepInfo
One step of a history, as the interface sees it.

Enums§

At
A point of a history the panel previews: a step (0: the start, a replaced step included) or a snapshot.
RefusalKind
Why an undo, a redo or a jump was refused.

Constants§

APP
The application’s own history: the value store’s steps.
CAP
How many steps a scope keeps by default, the oldest dropped first.
MERGE_WINDOW
How far apart, in seconds, two repeats on one target may come and still be one step.
SETTINGS
The settings window’s history: the values written from its form.

Functions§

may_undo_out_of_order
Whether undoing step out of order is allowed (VS Code’s rule): no later step of undo (oldest first) changed one of the same targets. targets_of names what a step changes. Err: the later step in the way, and the target it shares.
merges
Whether next joins the step that ended with prev: the same key and origin, less than MERGE_WINDOW later. The owner also stops merging when the focus leaves, after an undo or a redo, and across groups.
newest
The scope Ctrl+Z undoes among lines (the active scopes): the one whose head is newest, by time then by id; a later scope wins a tie. None: nothing to undo in any of them.
plan_jump
How to bring a scope to step to: after it, to is the head (0: the start, everything undone).