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

fix: Undo/Redo inside editor only + auto-focus after corrections - Moved listener back to editor element (capture:true) as user requested - Added editor.focus() after applySuggestionAtOffsets (line 432) - Added editor.focus() after applyAlternativeCorrection (line 474) - Added editor.focus() after dismissSuggestion (line 518) - After any correction/dismiss, editor auto-focuses so Ctrl+Z works immediately

Browse files
Files changed (1) hide show
  1. src/js/editor.js +9 -4
src/js/editor.js CHANGED
@@ -92,15 +92,15 @@ function initEditor() {
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
  }
@@ -109,7 +109,6 @@ function initEditor() {
109
  e.preventDefault();
110
  e.stopImmediatePropagation();
111
  editorRedo();
112
- editor.focus();
113
  return;
114
  }
115
  }
@@ -433,6 +432,8 @@ function applySuggestionAtOffsets(suggestion) {
433
  }
434
  }
435
  hideTooltip();
 
 
436
  analyzeTextDelayed();
437
  }
438
 
@@ -475,6 +476,8 @@ function applyAlternativeCorrection(suggestion, correctionText) {
475
  }
476
  }
477
  hideTooltip();
 
 
478
  analyzeTextDelayed();
479
  }
480
 
@@ -513,6 +516,8 @@ function dismissSuggestion(suggestion) {
513
  updateSuggestionsList(window.currentSuggestions);
514
  }
515
  hideTooltip();
 
 
516
  }
517
 
518
  function applySuggestionByIndex(index) {
 
92
 
93
  document.addEventListener('keydown', (e) => {
94
  if (e.key === 'Escape') hideTooltip();
95
+ });
96
 
97
+ // Custom Undo/Redo — on editor only, capture phase to beat 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.stopImmediatePropagation();
103
  editorUndo();
 
104
  return;
105
  }
106
  }
 
109
  e.preventDefault();
110
  e.stopImmediatePropagation();
111
  editorRedo();
 
112
  return;
113
  }
114
  }
 
432
  }
433
  }
434
  hideTooltip();
435
+ // Re-focus editor so Ctrl+Z works immediately after tooltip correction
436
+ const _ed = getEditorElement(); if (_ed) _ed.focus();
437
  analyzeTextDelayed();
438
  }
439
 
 
476
  }
477
  }
478
  hideTooltip();
479
+ // Re-focus editor so Ctrl+Z works immediately after tooltip correction
480
+ const _ed2 = getEditorElement(); if (_ed2) _ed2.focus();
481
  analyzeTextDelayed();
482
  }
483
 
 
516
  updateSuggestionsList(window.currentSuggestions);
517
  }
518
  hideTooltip();
519
+ // Re-focus editor so Ctrl+Z works immediately
520
+ const _ed3 = getEditorElement(); if (_ed3) _ed3.focus();
521
  }
522
 
523
  function applySuggestionByIndex(index) {