fix: Bugs on event listeners and closeAll

This commit is contained in:
2026-05-31 00:43:26 +05:30
parent 7b873bdbe8
commit 5082ed74c7
2 changed files with 23 additions and 13 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+22 -12
View File
@@ -822,6 +822,7 @@
document.querySelectorAll('.dd-item:not(.disabled)').forEach(item => { document.querySelectorAll('.dd-item:not(.disabled)').forEach(item => {
item.addEventListener('click', (e) => { item.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation(); e.stopPropagation();
closeAll(); closeAll();
handleAction(item.dataset.action); handleAction(item.dataset.action);
@@ -829,7 +830,7 @@
}); });
document.addEventListener('click', (e) => { document.addEventListener('click', (e) => {
if (!e.target.closest('#menu-bar')) closeAll(); if (e.target.closest('#menu-bar')) closeAll();
}); });
// -- Global Keyboard Shortcuts // -- Global Keyboard Shortcuts
@@ -880,6 +881,14 @@
if (e.key === 'Enter') { if (e.key === 'Enter') {
e.preventDefault(); e.preventDefault();
const focused = openDD.querySelector('.dd-item.dd-focused'); const focused = openDD.querySelector('.dd-item.dd-focused');
if (findBar.classList.contains('open')
&& gotoBar.classList.contains('open')
&& helpOverlay.classList.contains('open')
&& dialogOv.classList.contains('open')) {
e.preventDefault();
e.stopPropagation();
return;
}
if (focused && focused.dataset.action) { if (focused && focused.dataset.action) {
const action = focused.dataset.action; const action = focused.dataset.action;
closeAll(); closeAll();
@@ -1158,17 +1167,17 @@
} }
findInput.addEventListener('keydown', (e) => { findInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') { e.preventDefault(); syncSearch(); doFindNext(e.shiftKey ? -1 : 1); } if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); syncSearch(); doFindNext(e.shiftKey ? -1 : 1); }
if (e.key === 'Escape') closeAll(); if (e.key === 'Escape') closeAll();
}); });
replInput.addEventListener('keydown', (e) => { replInput.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeAll(); if (e.key === 'Escape') closeAll();
}); });
document.getElementById('btn-find-next').onclick = () => { syncSearch(); doFindNext(1); }; document.getElementById('btn-find-next').onclick = (e) => { e.preventDefault(); e.stopPropagation(); syncSearch(); doFindNext(1); };
document.getElementById('btn-find-prev').onclick = () => { syncSearch(); doFindNext(-1); }; document.getElementById('btn-find-prev').onclick = (e) => { e.preventDefault(); e.stopPropagation(); syncSearch(); doFindNext(-1); };
document.getElementById('btn-replace-one').onclick = () => { syncSearch(); doReplaceOne(); }; document.getElementById('btn-replace-one').onclick = (e) => { e.preventDefault(); e.stopPropagation(); syncSearch(); doReplaceOne(); };
document.getElementById('btn-replace-all').onclick = () => { syncSearch(); doReplaceAll(); }; document.getElementById('btn-replace-all').onclick = (e) => { e.preventDefault(); e.stopPropagation(); syncSearch(); doReplaceAll(); };
document.getElementById('btn-find-close').onclick = closeAll; document.getElementById('btn-find-close').onclick = closeAll;
function syncSearch() { function syncSearch() {
@@ -1280,15 +1289,17 @@
dialogTitle.textContent = title; dialogTitle.textContent = title;
dialogBody.innerHTML = bodyHTML; dialogBody.innerHTML = bodyHTML;
dialogOv.classList.add('open'); dialogOv.classList.add('open');
dialogOv.addEventListener('keydown', (e) => {
e.preventDefault();
});
dialogOv.addEventListener('click', (e) => {
e.preventDefault();
});
if (onReady) onReady(); if (onReady) onReady();
} }
dialogOv.addEventListener('click', (e) => {
if (e.target === dialogOv) closeAll();
});
// -- About Dialog // -- About Dialog
function showAbout() { function showAbout(e) {
showDialog('About Pascar', ` showDialog('About Pascar', `
<div style="text-align:center;padding:8px 0 4px;"> <div style="text-align:center;padding:8px 0 4px;">
<div style="font-size:22px;font-weight:bold;margin-bottom:6px;letter-spacing:1px;">Pascar</div> <div style="font-size:22px;font-weight:bold;margin-bottom:6px;letter-spacing:1px;">Pascar</div>
@@ -1302,7 +1313,6 @@
</div> </div>
<div class="dialog-buttons"><button class="btn primary" id="d-about-ok">OK</button></div> <div class="dialog-buttons"><button class="btn primary" id="d-about-ok">OK</button></div>
`, () => { `, () => {
document.getElementById('d-about-ok').focus();
document.getElementById('d-about-ok').addEventListener('click', closeAll); document.getElementById('d-about-ok').addEventListener('click', closeAll);
}); });
} }