Undoing and redoing from Javascript

How do I undo history directly from javacript? The reference mentions history.undo which seems to be what I want and what the history module uses internally for its keymap. However, calling it directly doesn’t seem to work.

When I try to run this code:

history.undo(view.state, view.dispatch);

I get the following error.

TypeError: state is not defined

I expect that undo, like most other changes, require dispatching a transaction to the view. The problem is that I haven’t been able to find a way to do this.

Apologies if the answer should be obvious.

Just call undo(view)—it takes a single argument, not two.

1 Like