Expand description
Undo (ADR 0014): histories owned by the kernel, routed by focus, projected by the interface.
-
The owner implements
History: its scopes (one history each: a document’s edit, a collection’s marks), their steps asStepInfos, and the requestsundo,redo,jumpandgroup. The host gives it (Host::history); without one, egui-pop’sStoreHistoryanswers over the value store’s application history (APP). The inverse of a step stays with the owner; the interface only reads and asks. -
Local scopes are a component’s own history, kept in the interface and never persisted: the theme editor’s draft, the settings window’s values (
StoreScopeover the store’sSETTINGShistory). A component registers one for its focus surface (Ctx::local_scope). -
Focus picks the history (
target). Ctrl+Z, outside a text field (which keeps its own undo), undoes in the innermost focused surface that has a local scope; nothing while a modal is open; otherwise, by theRoutingthe application sets:Routing::Newest(the default): the newest step among the owner’s scopes active in the window (a scope’s focus targets drawn; none: always active). Redo goes back to the scope last undone.Routing::Focus: the scope of the innermost focused surface that names one: the surface declared it (Ctx::history_target), or one of the owner’s scopes lists it among its focus targets (ScopeInfo::focus); when no focused surface names one (the menu bar, an empty spot, a panel without a history), the scope focused last in that window, while the owner still has it. Never the newest step of another scope: with no scope focused yet (at start-up), Ctrl+Z does nothing and says why (NOTHING_FOCUSED). Redo goes to the same scope.
Either way, the scope picked goes through the
pop.history.targetstep (STEP_TARGET) before Ctrl+Z, the Edit menu and the agents use it: a before-hook may name another scope (ornull: none). -
Undo, redo and jump are steps (ADR 0011):
edit.undo,edit.redoandedit.jump(STEP_JUMP), their arguments naming the scope, so a before-hook vetoes one or redirects it. A gesture in progress in the scope refuses them. Each answer is published:history.changed(the scope, its revision and head) orhistory.refused(the scope, the kind and the reason); the owner’s own moves (a new step) are published at the next pass. -
Merging and groups: writes with a merge key one second apart are one step (
values::Set::merge), the focus leaving seals them;History::groupopens an explicit group (an import, an agent’s request) whose steps are one entry. -
Beyond undo and redo, each a request with a default, so an owner that supports none of them keeps working: snapshots (named states, restored as a new step through
edit.restore), the history panel’s hover preview (hover), one step undone out of order (edit.undo_step, refused when a later step changed the same values), and the steps new steps replaced, reachable by a jump.History::featuressays which a scope supports;StoreHistorysupports them all.
use egui_pop_api::App;
use egui_pop_api::history;
use egui_pop_core::lock;
use egui_pop_model::commands::Origin;
use egui_pop_model::ids::OwnerId;
use egui_pop_model::values::{Change, Descriptor, Set, Value};
let app = App::builder().build(&egui::Context::default()).unwrap();
let h = app.handle();
let store = h.store();
lock(&store).declare(&OwnerId::USER, "doc/n", Descriptor::int("N", 0, 9, 0)).unwrap();
lock(&store).set(Set::new("doc/n", Change::To(Value::Int(3)), Origin::User)).unwrap();
assert!(history::can_undo(h));
assert!(history::undo(h, &Origin::User).ok());
assert_eq!(lock(&store).get("doc/n").unwrap().value, Value::Int(0));
assert_eq!(history::line(h, &history::APP).unwrap().redo.len(), 1);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.
- Merge
Mark - 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. - Preview
Change - 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.
- ScopeId
- A history (ADR 0014): one undo line, a document’s edit, a
collection’s marks, the settings window (
app,settings). - Scope
Info - 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.
- Step
Info - One step of a history, as the interface sees it.
- Store
History - egui-pop’s default owner: the value store’s histories, the
application’s (
APP) by default. - Store
Scope - A local scope over one of the value store’s histories: what is
written while
values::enter_historynames it goes there (the settings window’s form). - Walked
- An undo, a redo or a jump, as made.
Enums§
- Answer
- What the owner answers a request.
- At
- A point of a history the panel previews: a step (0: the start, a replaced step included) or a snapshot.
- Refusal
Kind - Why an undo, a redo or a jump was refused.
- Routing
- How Ctrl+Z picks among the owner’s scopes, outside a focused local
scope and a modal (
set_routing). - Target
- Where an undo or a redo goes.
- Walk
- What a walk asks: an undo, a redo, a jump to a step (0: the start), a snapshot restored, or one step undone out of order.
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.
- NOTHING_
FOCUSED - The rule
STEP_TARGETnames when, underRouting::Focus, no view was focused yet in the window: Ctrl+Z goes nowhere, and says so (egui-pop-history-nothing-focused). - SETTINGS
- The settings window’s history: the values written from its form.
- STEP_
JUMP - A jump to a step of a scope (
{ "scope", "to", "origin" },to0: the start): vetoable like an undo; its result names the steps walked. - STEP_
RESTORE - A snapshot restored (
{ "scope", "snapshot", "origin" }): a new step of the scope, vetoable like an undo. - STEP_
TARGET - Where Ctrl+Z or Ctrl+Shift+Z goes (
{ "scope", "redo", "rule" },ruleone offocus,last_focused,noneunderRouting::Focus,newestunderRouting::Newest): a before-hook may redirect it by naming anotherscope(null: none). Withnone,scopeisnull: no view was focused yet. Run quietly, whenever the target is read (the keys, the Edit menu, an agent’s undo without a scope): neither published nor traced. - STEP_
UNDO_ STEP - One step undone out of order (
{ "scope", "step", "origin" }, the history panel’s “Undo this step”): vetoable like an undo.
Traits§
- History
- The owner of the application’s histories, as the interface reaches it.
- Local
Scope - A component’s own history, kept in the interface (ADR 0014): the
theme editor’s draft, the settings window’s values. Registered for a
focus surface with
Ctx::local_scope: while the focus is in that surface, Ctrl+Z undoes here.
Functions§
- active
- The scopes the owner has active in the window now.
- ask
- An undo, a redo or a jump as an agent asks it (the
history.undo,history.redoandhistory.jumpcommands): inrequest.scope, or where the keys go when it isNone; refused unless the scope’s revision is stillif_rev; withdry_run, checked and answered, nothing changed. It runs through its step like the keys. - can_
redo - Whether Ctrl+Shift+Z would redo something now (
canRedo). - can_
undo - Whether Ctrl+Z would undo something now (
canUndo). - end_
preview - Ends the preview now (a click acts on the row: the state shown must be the real one first).
- features
- What the owner supports in a scope (nothing in a local scope).
- focused_
scope - The owner’s scope of the innermost focused surface that names one:
the history the surface declared (
Ctx::history_target), else a scope listing it among its focus targets. WhereRouting::Focussends Ctrl+Z. - forget_
snapshot - Deletes a snapshot, as
take_snapshottakes one; published ashistory.snapshot_deleted. - hover
- The pointer is on a point of a history (a row of rows drawn by the
host): the owner is asked to preview it, once while it stays there;
its answer. The preview ends (the owner told,
None) at the start of the second pass no row asks for it: the pointer left. Rows that want it ended in the pass the pointer leaves usehover_inandrows_drawn. - hover_
in hoverfrom a row of the rowsviewdraws:rows_drawnwith that view, once they are drawn, ends the preview when none of them asked for it in this pass.- jump
- Brings a scope to step
to(0: the start), through theedit.jumpstep. - label_
text - A label in the interface’s language: its message when it has one, else its text.
- last_
focused - The owner’s scope whose surface had the focus last in the window the
user works in (under
Routing::Focus), if any. - line
- A scope’s steps, local or the owner’s.
- may_
undo_ out_ of_ order - Whether undoing
stepout of order is allowed (VS Code’s rule): no later step ofundo(oldest first) changed one of the sametargets.targets_ofnames what a step changes.Err: the later step in the way, and the target it shares. - merges
- Whether
nextjoins the step that ended withprev: the same key and origin, less thanMERGE_WINDOWlater. The owner also stops merging when the focus leaves, after an undo or a redo, and across groups. - needs_
view - Whether, under
Routing::Focus, Ctrl+Z (redofalse) or Ctrl+Shift+Z goes nowhere only because no view was focused yet in the window, while some scope of the owner has a step to undo (or redo): the keys and the Edit menu stay live to say why (undoNeedsView,redoNeedsView). - 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,tois the head (0: the start, everything undone). - preview
- Asks the owner to preview a point of a scope (
None: the preview ends).None: no preview. - previewing
- The point previewed now, if any.
- redo
- Redoes where Ctrl+Shift+Z goes, through the
edit.redostep. - redo_in
- Redoes in a named scope, through the
edit.redostep. - redo_
label - What Ctrl+Shift+Z would redo.
- replaced
- A scope’s replaced steps, when its owner keeps them.
- restore
- Brings a scope back to one of its snapshots, as a new step, through
the
edit.restorestep. - routing
- How Ctrl+Z picks among the owner’s scopes now.
- rows_
drawn - The rows
viewdraws are drawn for this pass: a preview one of them asked for earlier and none asked for now ends here (the pointer left), and the window is drawn again with the real state. Nothing is asked while the pointer rests on a row: an idle window stays idle. - scope_
target - The scope named
scope: a local scope’s, else the owner’s. - scopes
- Every scope: the local ones, then the owner’s.
- set_
routing - Sets how Ctrl+Z picks among the owner’s scopes (
Routing). - snapshots
- A scope’s snapshots, oldest first (none in a local scope).
- store_
line - One of the store’s histories, as a
Line. - take_
snapshot - Takes a snapshot of a scope (where Undo goes when
scopeisNone): refused unless the scope’s revision is stillif_rev; withdry_run, the snapshot it would take. Published on the journal ashistory.snapshot_taken. - target
- Where Ctrl+Z (
redofalse) or Ctrl+Shift+Z goes now: the focused local scope; while a modal is open, nothing else; else the owner’s active scope with the newest head (for a redo, the scope last undone that can still redo, else the first active one that can).None: no history at all. - tips_of
- A line cut to its head and its next step.
- undo
- Undoes where Ctrl+Z goes (
target), through theedit.undostep. - undo_in
- Undoes in a named scope, through the
edit.undostep. - undo_
label - What Ctrl+Z would undo, as the Edit menu names it.
- undo_
step - Undoes one step of a scope out of order, through the
edit.undo_stepstep; the owner may refuse it. - unsupported
- What an owner refuses when it does not support a request.
- with_
owner - Runs
fon the owner: the host’s, else aStoreHistoryover the host’s store.Nonewhile the host dispatches a command.