Skip to main content

Module history

Module history 

Source
Expand description

Undo (ADR 0014): histories owned by the kernel, routed by focus, projected by the interface.

Experimental: may change in any release (docs/stability.md).
  • The owner implements History: its scopes (one history each: a document’s edit, a collection’s marks), their steps as StepInfos, and the requests undo, redo, jump and group. The host gives it (Host::history); without one, egui-pop’s StoreHistory answers 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 (StoreScope over the store’s SETTINGS history). 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 the Routing the 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.target step (STEP_TARGET) before Ctrl+Z, the Edit menu and the agents use it: a before-hook may name another scope (or null: none).

  • Undo, redo and jump are steps (ADR 0011): edit.undo, edit.redo and edit.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) or history.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::group opens 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::features says which a scope supports; StoreHistory supports 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.
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.
ScopeId
A history (ADR 0014): one undo line, a document’s edit, a collection’s marks, the settings window (app, settings).
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.
StoreHistory
egui-pop’s default owner: the value store’s histories, the application’s (APP) by default.
StoreScope
A local scope over one of the value store’s histories: what is written while values::enter_history names 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.
RefusalKind
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_TARGET names when, under Routing::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" }, to 0: 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" }, rule one of focus, last_focused, none under Routing::Focus, newest under Routing::Newest): a before-hook may redirect it by naming another scope (null: none). With none, scope is null: 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.
LocalScope
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.redo and history.jump commands): in request.scope, or where the keys go when it is None; refused unless the scope’s revision is still if_rev; with dry_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. Where Routing::Focus sends Ctrl+Z.
forget_snapshot
Deletes a snapshot, as take_snapshot takes one; published as history.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 use hover_in and rows_drawn.
hover_in
hover from a row of the rows view draws: rows_drawn with 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 the edit.jump step.
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 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.
needs_view
Whether, under Routing::Focus, Ctrl+Z (redo false) 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, to is 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.redo step.
redo_in
Redoes in a named scope, through the edit.redo step.
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.restore step.
routing
How Ctrl+Z picks among the owner’s scopes now.
rows_drawn
The rows view draws 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 scope is None): refused unless the scope’s revision is still if_rev; with dry_run, the snapshot it would take. Published on the journal as history.snapshot_taken.
target
Where Ctrl+Z (redo false) 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 the edit.undo step.
undo_in
Undoes in a named scope, through the edit.undo step.
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_step step; the owner may refuse it.
unsupported
What an owner refuses when it does not support a request.
with_owner
Runs f on the owner: the host’s, else a StoreHistory over the host’s store. None while the host dispatches a command.