Fix Ctrl+N/T: use window capture phase to intercept before browser chrome
document-level keydown bubbling phase is too late for browser-level shortcuts Ctrl+N (new window) and Ctrl+T (new tab). Moved handlers to a window.addEventListener('keydown', ..., true) capture-phase handler that fires before the browser chrome acts. Removed redundant document-level copies.
This commit is contained in:
@@ -1374,6 +1374,13 @@ document.addEventListener('keypress', e => { if (e.key === 'Enter') { if (docume
|
|||||||
document.getElementById('genModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeGen(); });
|
document.getElementById('genModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeGen(); });
|
||||||
document.getElementById('editModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeEdit(); });
|
document.getElementById('editModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeEdit(); });
|
||||||
// ==================== KEYBOARD SHORTCUTS ====================
|
// ==================== KEYBOARD SHORTCUTS ====================
|
||||||
|
// Window capture handler for browser-level shortcuts (Ctrl+N/T) that must be intercepted before chrome
|
||||||
|
window.addEventListener('keydown', function(e) {
|
||||||
|
if (!e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;
|
||||||
|
const inVault = document.getElementById('authSection').classList.contains('hidden');
|
||||||
|
if (e.code === 'KeyN' && inVault) { e.preventDefault(); if (!document.getElementById('addModal').classList.contains('show')) openAdd(); }
|
||||||
|
if (e.code === 'KeyT' && inVault) { e.preventDefault(); toggleTrash(); }
|
||||||
|
}, true);
|
||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
const tag = document.activeElement?.tagName;
|
const tag = document.activeElement?.tagName;
|
||||||
const isInput = tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
|
const isInput = tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
|
||||||
@@ -1433,6 +1440,7 @@ document.addEventListener('keydown', function(e) {
|
|||||||
|
|
||||||
// Only handle Ctrl+[key], no Shift/Alt/Meta
|
// Only handle Ctrl+[key], no Shift/Alt/Meta
|
||||||
if (!e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;
|
if (!e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;
|
||||||
|
if (!e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;
|
||||||
|
|
||||||
// Prevent browser defaults for ALL our shortcuts BEFORE dispatching
|
// Prevent browser defaults for ALL our shortcuts BEFORE dispatching
|
||||||
const code = e.code;
|
const code = e.code;
|
||||||
|
|||||||
Reference in New Issue
Block a user