Skip to content

Commit 0f019c1

Browse files
committed
fix: find & replace — Replace / Replace All buttons not working
Two bugs in editor-features.js: 1. wireFind('find-') constructed wrong IDs (find-find-input, find-replace-all) instead of actual HTML IDs (find-input, replace-all); no click handlers were attached to legacy bar Replace/All buttons 2. getActiveFindEls() always resolved to QAB elements because the QAB container has display:flex even when the full header is shown; performFind and replaceAll read from empty QAB inputs while user typed in legacy bar Fix: replaced wireFind(prefix) with wireFindSet(ids) using explicit ID maps; changed getActiveFindEls to check qabFindSection.style.display === 'flex'
1 parent b98595f commit 0f019c1

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Fix: Find & Replace — Replace / Replace All not working
2+
3+
## Root Cause
4+
5+
Two bugs in `js/editor-features.js`:
6+
7+
1. **Wrong element IDs in `wireFind('find-')`** — The prefix-based ID construction produced IDs like `find-find-input` and `find-replace-all` instead of the actual HTML IDs (`find-input`, `replace-all`). No click handlers were ever attached to the legacy find bar's Replace and Replace All buttons.
8+
9+
2. **`getActiveFindEls()` always resolved to QAB elements** — It checked `qab.style.display !== 'none'`, but the QAB container always has `display: flex`. So `performFind()`, `replaceOne()`, and `replaceAll()` read from the empty QAB inputs while the user was typing into the legacy find bar.
10+
11+
## Fix
12+
13+
- Replaced `wireFind(prefix)` with `wireFindSet(ids)` that takes explicit ID maps for each set of elements.
14+
- Changed `getActiveFindEls()` to check `qabFindSection.style.display === 'flex'` — only true when the QAB find section is explicitly opened.

js/editor-features.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@
423423

424424
// Resolve elements: prefer QAB inline if QAB is visible, else fall back to legacy bar
425425
function getActiveFindEls() {
426-
var qab = document.getElementById('quick-action-bar');
427-
var useQab = qab && qab.style.display !== 'none' && qabFindSection;
426+
// Use QAB inputs only when the QAB find section is explicitly open (display: flex)
427+
var useQab = qabFindSection && qabFindSection.style.display === 'flex';
428428
return {
429429
findInput: document.getElementById(useQab ? 'qab-find-input' : 'find-input'),
430430
replaceInput: document.getElementById(useQab ? 'qab-replace-input' : 'replace-input'),
@@ -559,15 +559,15 @@
559559
performFind();
560560
}
561561

562-
// Wire up BOTH sets of elements (legacy bar + QAB inline)
563-
function wireFind(prefix) {
564-
var fi = document.getElementById(prefix + 'find-input') || document.getElementById(prefix + '-find-input');
565-
var rt = document.getElementById(prefix + 'regex-toggle') || document.getElementById(prefix + '-regex-toggle');
566-
var fp = document.getElementById(prefix + 'find-prev') || document.getElementById(prefix + '-find-prev');
567-
var fn = document.getElementById(prefix + 'find-next') || document.getElementById(prefix + '-find-next');
568-
var ro = document.getElementById(prefix + 'replace-one') || document.getElementById(prefix + '-replace-one');
569-
var ra = document.getElementById(prefix + 'replace-all') || document.getElementById(prefix + '-replace-all');
570-
var ri = document.getElementById(prefix + 'replace-input') || document.getElementById(prefix + '-replace-input');
562+
// Wire up find/replace event listeners for a set of elements by their actual IDs
563+
function wireFindSet(ids) {
564+
var fi = document.getElementById(ids.findInput);
565+
var rt = document.getElementById(ids.regexToggle);
566+
var fp = document.getElementById(ids.findPrev);
567+
var fn = document.getElementById(ids.findNext);
568+
var ro = document.getElementById(ids.replaceOne);
569+
var ra = document.getElementById(ids.replaceAll);
570+
var ri = document.getElementById(ids.replaceInput);
571571
if (fi) fi.addEventListener('input', performFind);
572572
if (fp) fp.addEventListener('click', findPrev);
573573
if (fn) fn.addEventListener('click', findNext);
@@ -589,13 +589,21 @@
589589
if (ri) ri.addEventListener('keydown', function (e) { if (e.key === 'Escape') M.closeFindBar(); });
590590
}
591591

592-
// Wire legacy bar elements
593-
wireFind('find-');
592+
// Wire legacy bar elements (IDs: find-input, replace-input, find-prev, etc.)
593+
wireFindSet({
594+
findInput: 'find-input', replaceInput: 'replace-input',
595+
regexToggle: 'find-regex-toggle', findPrev: 'find-prev', findNext: 'find-next',
596+
replaceOne: 'replace-one', replaceAll: 'replace-all'
597+
});
594598
var findCloseBtn = document.getElementById('find-close');
595599
if (findCloseBtn) findCloseBtn.addEventListener('click', M.closeFindBar);
596600

597-
// Wire QAB inline elements
598-
wireFind('qab-');
601+
// Wire QAB inline elements (IDs: qab-find-input, qab-replace-input, etc.)
602+
wireFindSet({
603+
findInput: 'qab-find-input', replaceInput: 'qab-replace-input',
604+
regexToggle: 'qab-regex-toggle', findPrev: 'qab-find-prev', findNext: 'qab-find-next',
605+
replaceOne: 'qab-replace-one', replaceAll: 'qab-replace-all'
606+
});
599607

600608
// ========================================
601609
// WORD WRAP TOGGLE

0 commit comments

Comments
 (0)