mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Implemented undo and redo mechanism for drawing signature (#3152)
# Description of Changes Please provide a summary of the changes, including: Added undo and redo button for drawing signature, and provided translation properties for the buttons Closes [#(2454)](https://github.com/Stirling-Tools/Stirling-PDF/issues/2454) --- ## Checklist ### General - [✅](https://emojipedia.org/check-mark-button)I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅](https://emojipedia.org/check-mark-button) I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) -[✅](https://emojipedia.org/check-mark-button)I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [✅](https://emojipedia.org/check-mark-button) I have performed a self-review of my own code -[✅](https://emojipedia.org/check-mark-button) My changes generate no new warnings ### UI Changes (if applicable)  ### Testing (if applicable) - [✅](https://emojipedia.org/check-mark-button) I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
@@ -1,10 +1,48 @@
|
||||
const signaturePadCanvas = document.getElementById('drawing-pad-canvas');
|
||||
const undoButton = document.getElementById("signature-undo-button");
|
||||
const redoButton = document.getElementById("signature-redo-button");
|
||||
const signaturePad = new SignaturePad(signaturePadCanvas, {
|
||||
minWidth: 1,
|
||||
maxWidth: 2,
|
||||
penColor: 'black',
|
||||
});
|
||||
|
||||
let undoData = [];
|
||||
|
||||
signaturePad.addEventListener("endStroke", () => {
|
||||
undoData = [];
|
||||
});
|
||||
|
||||
window.addEventListener("keydown", (event) => {
|
||||
switch (true) {
|
||||
case event.key === "z" && event.ctrlKey:
|
||||
undoButton.click();
|
||||
break;
|
||||
case event.key === "y" && event.ctrlKey:
|
||||
redoButton.click();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
function undoDraw() {
|
||||
const data = signaturePad.toData();
|
||||
|
||||
if (data && data.length > 0) {
|
||||
const removed = data.pop();
|
||||
undoData.push(removed);
|
||||
signaturePad.fromData(data);
|
||||
}
|
||||
}
|
||||
|
||||
function redoDraw() {
|
||||
|
||||
if (undoData.length > 0) {
|
||||
const data = signaturePad.toData();
|
||||
data.push(undoData.pop());
|
||||
signaturePad.fromData(data);
|
||||
}
|
||||
}
|
||||
|
||||
function addDraggableFromPad() {
|
||||
if (signaturePad.isEmpty()) return;
|
||||
const startTime = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user