Index

History

MMO.editor · 1 symbol · generated 30 Sep 2026

class

History

History.js:18

The undo/redo stack of one editable region.

class MMO.editor.History
Namespace
MMO.editor
The editor keeps its own instead of the browser's: the browser's only knows about what `execCommand` did, and half of what the tools do (colours, code, tables, a paste that is cleaned) is plain dom work it cannot undo. A step is the region's html and where the selection was, so undoing puts the caret back where it was too. Typing is not recorded key by key: `MMO.editor.History#touch` groups what is typed until a pause.
const history = new MMO.editor.History(region); history.commit(); //after a change history.undo(); //puts the previous html and selection back

Index

constructor(root, max)
reset()Forget every step: the current content becomes the first one.
snapshot()
commit()Record the current content as a new step, if it changed.
touch(delay)Record the current content after a pause: what is typed in one go is undone in one go.
cancelTimer()[internal]
canUndo()
canRedo()
undo()Go back one step
redo()Go forward one step
restore(step, fallbackRange)[internal] Put a step back in the region

Methods11

constructor(root, max)

History.js:23
constructor(root, max = 200)
rootElementthe editable region
max = 200numberhow many steps are kept

reset()

History.js:35

Forget every step: the current content becomes the first one.

reset()

snapshot()

History.js:44
snapshot()
returnshtml: string, range: ?Object} the region as it is now

commit()

History.js:56

Record the current content as a new step, if it changed.

commit()
returnsbooleantrue when a step was added

touch(delay)

History.js:78

Record the current content after a pause: what is typed in one go is undone in one go.

touch(delay = 600)
delay = 600numberin ms

undo()

History.js:111

Go back one step

undo()
returnsbooleanfalse when there was nothing to undo

redo()

History.js:124

Go forward one step

redo()
returnsbooleanfalse when there was nothing to redo

restore(step, fallbackRange)

History.js:136

[internal] Put a step back in the region

restore(step, fallbackRange = null)
step
fallbackRange = null?Objectwhere the selection goes when the step has none