Slate
ExamplesGitHubSlack
main
main
  • Introduction
  • Walkthroughs
    • Installing Slate
    • Adding Event Handlers
    • Defining Custom Elements
    • Applying Custom Formatting
    • Executing Commands
    • Saving to a Database
    • Enabling Collaborative Editing
    • Using the Bundled Source
  • Concepts
    • Interfaces
    • Nodes
    • Locations
    • Transforms
    • Operations
    • Commands
    • Editor
    • Plugins
    • Rendering
    • Serializing
    • Normalizing
    • TypeScript
    • Migrating
  • API
    • Transforms
    • Node Types
      • Editor
      • Element
      • Node
      • NodeEntry
      • Text
    • Location Types
      • Location
      • Path
      • PathRef
      • Point
      • PointEntry
      • PointRef
      • Range
      • RangeRef
      • Span
    • Operation Types
      • Operation
    • Scrubber
  • Libraries
    • Slate React
      • withReact
      • ReactEditor
      • Hooks
      • Slate Component
      • Editable Component
      • Event Handling
    • Slate History
      • withHistory
      • HistoryEditor
      • History
    • Slate Hyperscript
  • General
    • Resources
    • Contributing
    • Changelog
    • FAQ
Powered by GitBook
On this page
  • Static methods
  • Undo and Redo
  • Merging and Saving
  • Check methods
  • Instance methods
  1. Libraries
  2. Slate History

HistoryEditor

PreviouswithHistoryNextHistory

Last updated 6 months ago

The HistoryEditor interface is added to the Editor when it is instantiated using the withHistory method.

const [editor] = useState(() => withReact(withHistory(createEditor())))

This adds properties to editor that enables undo and redo in Slate.

There are also static methods for working with the Editor's undo/redo history.

export interface HistoryEditor extends BaseEditor {
  history: History
  undo: () => void
  redo: () => void
  writeHistory: (stack: 'undos' | 'redos', batch: any) => void
}

Static methods

Undo and Redo

HistoryEditor.redo(editor: HistoryEditor): void

Redo to the next saved state.

HistoryEditor.undo(editor: HistoryEditor): void

Undo to the previous saved state.

Merging and Saving

HistoryEditor.withMerging(editor: HistoryEditor, fn: () => void): void

Apply a series of changes inside a synchronous fn, These operations will be merged into the previous history.

HistoryEditor.withNewBatch(editor: HistoryEditor, fn: () => void): void

Apply a series of changes inside a synchronous fn, ensuring that the first operation starts a new batch in the history. Subsequent operations will be merged as usual.

HistoryEditor.withoutMerging(editor: HistoryEditor, fn: () => void): void

Apply a series of changes inside a synchronous fn, without merging any of the new operations into previous save point in the history.

HistoryEditor.withoutSaving(editor: HistoryEditor, fn: () => void): void

Apply a series of changes inside a synchronous fn, without saving any of their operations into the history.

Check methods

HistoryEditor.isHistoryEditor(value: any): value is HistoryEditor

Check if a value is a HistoryEditor (i.e. it has the HistoryEditor interface).

HistoryEditor.isMerging(editor: HistoryEditor): boolean | undefined

Get the merge flag's current value.

HistoryEditor.isSaving(editor: HistoryEditor): boolean | undefined

Get the saving flag's current value.

Instance methods

undo(): void

Undo the last batch of operations

redo(): void

Redo the last undone batch of operations

writeHistory(stack: 'undos'| 'redos', batch: any) => void

Push a batch of operations as either undos or redos onto editor.undos or editor.redos

Static methods
Undo and Redo
Merging and Saving
Check methods
Instance methods