Skip to content

Commit 51cb3f7

Browse files
committed
undo option
1 parent 7b0fe6e commit 51cb3f7

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

js/annotation_editor.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@
301301
width: 20px;
302302
height: 20px;
303303
}
304+
305+
.tool-button:disabled {
306+
opacity: 0.3;
307+
cursor: not-allowed;
308+
pointer-events: none;
309+
}
310+
311+
.tool-button:disabled:hover {
312+
transform: none;
313+
background: var(--color-surface);
314+
}
304315
</style>
305316
</head>
306317
<body>
@@ -310,6 +321,7 @@
310321
<div class="shortcuts">
311322
<span><span class="shortcut-key">A</span> Arrow</span>
312323
<span><span class="shortcut-key">R</span> Rectangle</span>
324+
<span><span class="shortcut-key">Ctrl+Z</span> Undo</span>
313325
<span><span class="shortcut-key">Esc</span> Cancel</span>
314326
<span><span class="shortcut-key">Ctrl+Enter</span> Save</span>
315327
</div>
@@ -332,6 +344,12 @@
332344
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
333345
</svg>
334346
</button>
347+
<button class="tool-button" id="undo-button" data-tooltip="Undo (Ctrl+Z)" disabled>
348+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
349+
<polyline points="1 4 1 10 7 10"></polyline>
350+
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path>
351+
</svg>
352+
</button>
335353
</div>
336354

337355
<div class="toolbar-section">

js/annotation_editor.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
img.src = screenshotDataUrl;
3737
}
3838

39+
// Undo last annotation
40+
function undo() {
41+
if (annotations.length === 0) return;
42+
annotations.pop();
43+
redrawCanvas();
44+
updateUndoButton();
45+
}
46+
47+
// Enable/disable undo button based on annotations count
48+
function updateUndoButton() {
49+
document.getElementById('undo-button').disabled = annotations.length === 0;
50+
}
51+
3952
// Redraw canvas with base image and all annotations
4053
function redrawCanvas() {
4154
// Clear canvas
@@ -168,6 +181,7 @@
168181
}
169182

170183
redrawCanvas();
184+
updateUndoButton();
171185
});
172186

173187
// Tool selection
@@ -185,6 +199,9 @@
185199
canvas.className = 'tool-rectangle';
186200
});
187201

202+
// Undo button
203+
document.getElementById('undo-button').addEventListener('click', undo);
204+
188205
// Action buttons
189206
document.getElementById('save-with-annotations').addEventListener('click', () => {
190207
// Get final canvas as data URL
@@ -228,6 +245,9 @@
228245
document.getElementById('arrow-tool').click();
229246
} else if (e.key === 'r' || e.key === 'R') {
230247
document.getElementById('rectangle-tool').click();
248+
} else if (e.key === 'z' && (e.ctrlKey || e.metaKey)) {
249+
e.preventDefault();
250+
undo();
231251
} else if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
232252
document.getElementById('save-with-annotations').click();
233253
}

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Exploratory Testing Extension",
4-
"version": "4.0.1",
4+
"version": "4.1.0",
55
"description": "Chrome extension for exploratory testing",
66
"permissions": [
77
"storage",

0 commit comments

Comments
 (0)