Well well well.. finally I’ve done a script to Clear a Document Undo History, so I’ll have no more the need of close and reopen the Document.
I post this script source in this new topic because I think it’s too long to put it in the “Storeroom of scripts” topic [Storeroom of scripts].
It relies on the Krita “Snapshot Docker”, basically I noticed that when you switch to a selected snapshot the document undo history is deleted, so this is what the script does.
Unfortunately when the “Snapshot Docker” switches to a snapshot sometimes Krita crashes, so it’s better to save the works before.
It has also a section that can be translated to localize the text.
Tested with:
- Win10 - Krita 5.2.14 “Real” Portable
- Win10 - Krita 5.3.0 prealpha “Real” Portable (krita-x64-5.3.0 prealpha ff1d7054 2025-12-30)
With “Real” Portable I mean a portable version launched with a Batch file setting USERPROFILE variable to a relative path [example here: REAL Portable Versions - #17 by ElderlyGlek - Thank you @ElderlyGlek !!! - I slightly changed this a little] (and something else modified due absolute paths change needs: kritarc and G’MIC-Qt paths - for now). All this aimed to have a real portable version which stores all things under a movable folder.
Maybe it’s not perfect, but seems it works, and about the script I think it should work fine in other “regular” Krita installations.
Anyway who wants can try and use it, I’ll be happy to know if it will be useful
and please tell me if you find bugs.
In my installation I’ve named the script file “SK_CLEAR_UNDO_HISTORY.py” and I’ve put it in “Krita resources folder”/pykrita/“My scripts folder”.
I use it with the “Ten Scripts” plugin and I’ve assigned the Keyboard Shortcut CTRL+F12 to the script execution.
Many huge thanks to @AkiR for the super-useful code and of course also to @mighty_noob for the super-useful question
[How to list snapshot and remove by name using python API - #4 by AkiR]
Here some screenshots:
Here SK_CLEAR_UNDO_HISTORY.py:
#-------------------------------------------------------------------------------
# SK_CLEAR_UNDO_HISTORY.py
# CLEAR DOCUMENT UNDO HISTORY SCRIPT (RELIES ON KRITA SNAPSHOT DOCKER)
# AUTHOR: Skess01
# LICENSE: CC-BY-SA
# VERSIONS
# - 2026-01-11 - V1.00
#-------------------------------------------------------------------------------
from krita import Krita
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QListView, QMessageBox
app = Krita.instance()
document = app.activeDocument()
new_line = "\n"
mess_line = "--------------------------------------------------------------------------------------------------------------" + new_line
#-------------------------------------------------------------------------------
# LOCALIZATION - ORIGINAL ENGLISH PART
# Keep it as is to not loose the original version
#-------------------------------------------------------------------------------
msg_confirmation_title = "Clear Document Undo History"
msg_error_title = "Clear Document Undo History"
error_message_no_docs = "ERROR - There are no open Documents!"
error_message_no_docker = "ERROR - Snapshot Docker not found!"
mess_prologue_1 = "IMPORTANT INFORMATION" + new_line
mess_prologue_2 = "This script relies on Krita SNAPSHOT DOCKER which SOMETIMES CRASHES KRITA, CLOSING IT." + new_line + new_line
mess_warning_line = "> W A R N I N G !" + new_line
mess_mod_1 = "> There is an UNSAVED DOCUMENT"
mess_mod_1a = "> There are" # AFTER THIS THERE IS THE NUMBER OF UNSAVED DOCUMENTS
mess_mod_1b = "UNSAVED DOCUMENTS" # BEFORE THIS THERE IS THE NUMBER OF UNSAVED DOCUMENTS
mess_mod_2 = " - Krita COULD CRASH executing this operation!" + new_line
mess_save = "> IF YOU WANT TO SAVE YOUR WORK BEFORE > Cancel THIS OPERATION!" + new_line
mess_question = "Do you confirm COMPLETE DOCUMENT HISTORY DELETION?"
#-------------------------------------------------------------------------------
# LOCALIZATION - PART THAT CAN BE TRANSLATED
# All the text (between double quotes) in this section can be translated
# in another language to localize the script
#-------------------------------------------------------------------------------
msg_confirmation_title = "Clear Document Undo History"
msg_error_title = "Clear Document Undo History"
error_message_no_docs = "ERROR - There are no open Documents!"
error_message_no_docker = "ERROR - Snapshot Docker not found!"
mess_prologue_1 = "IMPORTANT INFORMATION" + new_line
mess_prologue_2 = "This script relies on Krita SNAPSHOT DOCKER which SOMETIMES CRASHES KRITA, CLOSING IT." + new_line + new_line
mess_warning_line = "> W A R N I N G !" + new_line
mess_mod_1 = "> There is an UNSAVED DOCUMENT"
mess_mod_1a = "> There are" # AFTER THIS THERE IS THE NUMBER OF UNSAVED DOCUMENTS
mess_mod_1b = "UNSAVED DOCUMENTS" # BEFORE THIS THERE IS THE NUMBER OF UNSAVED DOCUMENTS
mess_mod_2 = " - Krita COULD CRASH executing this operation!" + new_line
mess_save = "> IF YOU WANT TO SAVE YOUR WORK BEFORE > Cancel THIS OPERATION!" + new_line
mess_question = "Do you confirm COMPLETE DOCUMENT HISTORY DELETION?"
#-------------------------------------------------------------------------------
# LOCALIZATION - END
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def clear_history():
for docker in app.dockers():
if docker.objectName() == 'Snapshot': # SNAPSHOT DOCKER FOUND
docker_view = docker.findChild(QListView)
docker_view_model = docker_view.model()
app.action('create_snapshot').trigger() # CREATE SNAPSHOT
docker_row = docker_view_model.rowCount() - 1 # FIND SNAPSHOT LAST ROW
docker_index = docker_view_model.index(int(docker_row), 0) # FIND SNAPSHOT INDEX
docker_view.setCurrentIndex(docker_index) # SELECT SNAPSHOT
app.action('switchto_snapshot').trigger() # SWITCH TO SNAPSHOT
app.action('remove_snapshot').trigger() # REMOVE SNAPSHOT
#-------------------------------------------------------------------------------
def confirmation_message():
mess_prologue = mess_prologue_1 + mess_prologue_2
mess_mod = ""
modified = 0
for doc in app.documents():
if doc.modified():
modified = modified + 1
if modified > 0:
mess_mod = mess_line + mess_warning_line + mess_mod_1 + mess_mod_2 + mess_save + mess_line + new_line
if modified > 1:
mess_mod = mess_line + mess_warning_line + mess_mod_1a + " " + str(modified) + " " + mess_mod_1b + mess_mod_2 + mess_save + mess_line + new_line
message = mess_prologue + mess_mod + mess_question
msg_confirmation = QMessageBox()
msg_confirmation.setWindowTitle(msg_confirmation_title)
msg_confirmation.setText(message)
msg_confirmation.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
if modified > 0:
msg_confirmation.setDefaultButton(QMessageBox.Cancel)
msg_confirmation.setIcon(QMessageBox.Warning)
confirmation = msg_confirmation.exec()
if confirmation == QMessageBox.Ok:
clear_history()
msg_confirmation.close()
#-------------------------------------------------------------------------------
def error_message(err_message):
msg_error = QMessageBox()
msg_error.setWindowTitle(msg_error_title)
msg_error.setText(err_message)
msg_error.setStandardButtons(QMessageBox.Ok)
msg_error.setIcon(QMessageBox.Critical)
msg_error.exec()
msg_error.close()
#-------------------------------------------------------------------------------
errors = False
docker_ok = False
if document is None:
errors = True
error_message(error_message_no_docs)
else:
for docker in app.dockers():
if docker.objectName() == 'Snapshot':
docker_ok = True
if not docker_ok:
errors = True
error_message(error_message_no_docker)
if not errors:
confirmation_message()
#-------------------------------------------------------------------------------


