diff --git a/ios/Sources/GutenbergKit/Sources/EditorViewController.swift b/ios/Sources/GutenbergKit/Sources/EditorViewController.swift index 25a4c5c..3811864 100644 --- a/ios/Sources/GutenbergKit/Sources/EditorViewController.swift +++ b/ios/Sources/GutenbergKit/Sources/EditorViewController.swift @@ -207,6 +207,16 @@ public final class EditorViewController: UIViewController, GutenbergEditorContro return EditorTitleAndContent(title: title, content: content) } + /// Steps backwards in the editor history state + public func undo() { + evaluate("editor.undo();") + } + + /// Steps forwards in the editor history state + public func redo() { + evaluate("editor.redo();") + } + /// Enables code editor. public var isCodeEditorEnabled: Bool = false { didSet { diff --git a/src/components/visual-editor/index.jsx b/src/components/visual-editor/index.jsx index cea4e37..b279762 100644 --- a/src/components/visual-editor/index.jsx +++ b/src/components/visual-editor/index.jsx @@ -72,7 +72,7 @@ function VisualEditor({ post }) { const postContentRef = useRef(post.content); const { addEntities, editEntityRecord, receiveEntityRecords } = useDispatch(coreStore); - const { setEditedPost, setupEditor } = useDispatch(editorStore); + const { setEditedPost, setupEditor, undo, redo } = useDispatch(editorStore); const { getEditedPostAttribute, getEditedPostContent } = useSelect(editorStore); @@ -171,6 +171,16 @@ function VisualEditor({ post }) { }; }; + editor.undo = () => { + // Do not return the `Promise` return value to avoid host errors. + undo(); + }; + + editor.redo = () => { + // Do not return the `Promise` return value to avoid host errors. + redo(); + }; + const blockEditorSettings = useBlockEditorSettings( editorSettings, post.type,