youssefreda9 commited on
Commit
10f7c9d
·
1 Parent(s): 9641a79

fix: Undo/Redo now works after spelling corrections - Moved keydown listener from editor to document with capture:true - Uses stopImmediatePropagation to prevent browser native undo - Auto-focuses editor after undo/redo - Works even when tooltip click steals focus from editor

Browse files
Files changed (1) hide show
  1. src/js/editor.js +8 -5
src/js/editor.js CHANGED
@@ -92,22 +92,25 @@ function initEditor() {
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);
 
92
 
93
  document.addEventListener('keydown', (e) => {
94
  if (e.key === 'Escape') hideTooltip();
 
95
 
96
+ // Custom Undo/Redo — capture phase on document fires BEFORE browser native undo
97
+ // Must be on document (not editor) so it works after tooltip clicks steal focus
98
  if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
99
  if (_undoStack.length > 0) {
100
  e.preventDefault();
101
+ e.stopImmediatePropagation();
102
  editorUndo();
103
+ editor.focus();
104
+ return;
105
  }
106
  }
107
  if ((e.ctrlKey || e.metaKey) && (e.key === 'y' || (e.key === 'z' && e.shiftKey))) {
108
  if (_redoStack.length > 0) {
109
  e.preventDefault();
110
+ e.stopImmediatePropagation();
111
  editorRedo();
112
+ editor.focus();
113
+ return;
114
  }
115
  }
116
  }, true);