Skip to content
Guides

Undo and Redo

The docViewer class of ContentEditHistoryManager saves the history of the current page and provides undo and redo functionalities.

Undo refers to reversing previous actions and restoring the document to its previous state. After a user operates, if they find the result unsatisfactory, they can undo the step to revert to the previous state. This helps prevent data loss due to mistakes or dissatisfaction with the outcome.

Redo is a complementary feature to undo; it allows users to reapply previously undone actions, restoring the system state to its state before the undo. Redo is typically used when a user realizes that the initially undone actions were necessary after one or multiple undo steps.

This example shows how to undo and redo:

javascript
// Get the index of the current page (starting from 0).
const pageIndex = Core.getCurrentPage() - 1;

// undo.
if (await docViewer.getContentEditHistoryManager()[pageIndex].canUndo())
{
    await docViewer.getContentEditHistoryManager()[pageIndex].undo();
}
// redo.
if (await docViewer.getContentEditHistoryManager()[pageIndex].canRedo())
{
    await docViewer.getContentEditHistoryManager()[pageIndex].redo();
}