d_history() creates an undo/redo stack for dragmapr_state objects. Push
a checkpoint with d_history_push() after each meaningful edit, then step
backwards with d_undo() and forwards with d_redo(). Pushing a new
checkpoint clears the redo stack, matching familiar editor behaviour.
Value
d_history() returns a dragmapr_history object;
d_history_push() returns the history invisibly; d_undo() and
d_redo() return the restored dragmapr_state.
Details
The history object has reference semantics: d_history_push(), d_undo(),
and d_redo() modify it in place, so reassignment is optional.
Examples
h <- d_history()
s0 <- d_state(
region_offsets = data.frame(region = "A", dx_m = 0, dy_m = 0)
)
d_history_push(h, s0)
s1 <- d_nudge(s0, "A", dx_m = 50)
d_history_push(h, s1)
back <- d_undo(h) # s0 offsets again
fwd <- d_redo(h) # s1 offsets again
d_state_equal(back, s0)
#> [1] TRUE
d_state_equal(fwd, s1)
#> [1] TRUE
