Allow Ctrl+Z to undo the removal of images/tasks

This commit is contained in:
cmdr2 2023-03-28 17:13:37 +05:30
parent 9ee17ec5f1
commit 03800a45e0
2 changed files with 10 additions and 1 deletions

View File

@ -298,7 +298,7 @@
<button id="clear-all-previews" class="secondaryButton"><i class="fa-solid fa-trash-can icon"></i> Clear All</button> <button id="clear-all-previews" class="secondaryButton"><i class="fa-solid fa-trash-can icon"></i> Clear All</button>
<button class="tertiaryButton" id="show-download-popup"><i class="fa-solid fa-download"></i> Download images</button> <button class="tertiaryButton" id="show-download-popup"><i class="fa-solid fa-download"></i> Download images</button>
<div class="display-settings"> <div class="display-settings">
<button id="undo" class="displayNone tertiaryButton"> <button id="undo" class="displayNone primaryButton">
Undo <i class="fa-solid fa-rotate-left icon"></i> Undo <i class="fa-solid fa-rotate-left icon"></i>
<span class="simple-tooltip left">Undo last remove</span> <span class="simple-tooltip left">Undo last remove</span>
</button> </button>

View File

@ -278,6 +278,9 @@ function undoableRemove(element, doubleUndo=false) {
function undoRemove() { function undoRemove() {
let data = undoBuffer.pop() let data = undoBuffer.pop()
if (!data) {
return
}
if (data.next == null) { if (data.next == null) {
data.parent.appendChild(data.element) data.parent.appendChild(data.element)
} else { } else {
@ -294,6 +297,12 @@ function undoRemove() {
undoButton.addEventListener('click', () => { undoRemove() }) undoButton.addEventListener('click', () => { undoRemove() })
document.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.key === 'z' && e.target == document.body) {
undoRemove()
}
})
function showImages(reqBody, res, outputContainer, livePreview) { function showImages(reqBody, res, outputContainer, livePreview) {
let imageItemElements = outputContainer.querySelectorAll('.imgItem') let imageItemElements = outputContainer.querySelectorAll('.imgItem')
if(typeof res != 'object') return if(typeof res != 'object') return