diff --git a/docs/reference/models/state.md b/docs/reference/models/state.md index 12ca0f59e..f158b47ee 100644 --- a/docs/reference/models/state.md +++ b/docs/reference/models/state.md @@ -22,6 +22,8 @@ For convenience, in addition to transforms, many of the [`Selection`](./selectio - [`fragment`](#fragment) - [`inlines`](#inlines) - [`texts`](#texts) + - [`hasUndo`](#hasundo) + - [`hasRedo`](#hasredo) - [Selection-like Properties](#selection-like-properties) - [`{edge}Key`](#edgekey) - [`{edge}Offset`](#edgeoffset) @@ -32,7 +34,7 @@ For convenience, in addition to transforms, many of the [`Selection`](./selectio - [`isFocused`](#isfocused) - [`isForward`](#isForward) - [Static Methods](#static-methods) - - [`State.create`](#statecreate) + - [`State.create`](#statecreate) - [Methods](#methods) - [`transform`](#transform) @@ -42,7 +44,7 @@ For convenience, in addition to transforms, many of the [`Selection`](./selectio ```js State({ document: Document, - selection: Selection + selection: Selection }) ``` @@ -97,6 +99,15 @@ Get a list of the lowest-depth [`Inline`](./inline.md) nodes in the current sele Get a list of the [`Text`](./text.md) nodes in the current selection. +### `hasUndo` +`Boolean` + +Whether there are undoable events. + +### `hasRedo` +`Boolean` + +Whether there are redoable events. ## Selection-like Properties diff --git a/lib/models/state.js b/lib/models/state.js index 28e7e4cc0..4962cf2b2 100644 --- a/lib/models/state.js +++ b/lib/models/state.js @@ -58,6 +58,26 @@ class State extends new Record(DEFAULTS) { return 'state' } + /** + * Is there undoable events? + * + * @return {Boolean} hasUndo + */ + + get hasUndo() { + return this.history.undos.size > 0 + } + + /** + * Is there redoable events? + * + * @return {Boolean} hasRedo + */ + + get hasRedo() { + return this.history.redos.size > 0 + } + /** * Is the current selection blurred? *