Commit ·
e1ecaac
1
Parent(s): 55abf68
fix: Use capture phase on editor for Ctrl+Z/Y to intercept before browser native undo - Listener now on editor element with capture:true instead of document - Added stopPropagation to prevent browser native undo from also firing - Ensures corrections/dismissals can be properly undone
Browse files- src/js/editor.js +7 -2
src/js/editor.js
CHANGED
|
@@ -92,20 +92,25 @@ function initEditor() {
|
|
| 92 |
|
| 93 |
document.addEventListener('keydown', (e) => {
|
| 94 |
if (e.key === 'Escape') hideTooltip();
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
|
| 97 |
if (_undoStack.length > 0) {
|
| 98 |
e.preventDefault();
|
|
|
|
| 99 |
editorUndo();
|
| 100 |
}
|
| 101 |
}
|
| 102 |
if ((e.ctrlKey || e.metaKey) && (e.key === 'y' || (e.key === 'z' && e.shiftKey))) {
|
| 103 |
if (_redoStack.length > 0) {
|
| 104 |
e.preventDefault();
|
|
|
|
| 105 |
editorRedo();
|
| 106 |
}
|
| 107 |
}
|
| 108 |
-
});
|
| 109 |
|
| 110 |
document.addEventListener('click', (e) => {
|
| 111 |
const popover = document.getElementById('editor-tooltip');
|
|
|
|
| 92 |
|
| 93 |
document.addEventListener('keydown', (e) => {
|
| 94 |
if (e.key === 'Escape') hideTooltip();
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
// Custom Undo/Redo — use capture phase on editor to intercept BEFORE browser native undo
|
| 98 |
+
editor.addEventListener('keydown', (e) => {
|
| 99 |
if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
|
| 100 |
if (_undoStack.length > 0) {
|
| 101 |
e.preventDefault();
|
| 102 |
+
e.stopPropagation();
|
| 103 |
editorUndo();
|
| 104 |
}
|
| 105 |
}
|
| 106 |
if ((e.ctrlKey || e.metaKey) && (e.key === 'y' || (e.key === 'z' && e.shiftKey))) {
|
| 107 |
if (_redoStack.length > 0) {
|
| 108 |
e.preventDefault();
|
| 109 |
+
e.stopPropagation();
|
| 110 |
editorRedo();
|
| 111 |
}
|
| 112 |
}
|
| 113 |
+
}, true);
|
| 114 |
|
| 115 |
document.addEventListener('click', (e) => {
|
| 116 |
const popover = document.getElementById('editor-tooltip');
|