Fix Ctrl+N/T: use e.key instead of e.code, remove duplicate guard
Switched from e.code (physical key position) to e.key (character value) which is more reliable across keyboard layouts and browsers. Also removed duplicate Ctrl guard line.
This commit is contained in:
@@ -1374,13 +1374,7 @@ document.addEventListener('keypress', e => { if (e.key === 'Enter') { if (docume
|
||||
document.getElementById('genModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeGen(); });
|
||||
document.getElementById('editModal').addEventListener('click', e => { if (e.target === e.currentTarget) closeEdit(); });
|
||||
// ==================== 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);
|
||||
// Prevent browser Ctrl+N/T — use capture on documentElement + fallback on document for reliability
|
||||
document.addEventListener('keydown', function(e) {
|
||||
const tag = document.activeElement?.tagName;
|
||||
const isInput = tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
|
||||
@@ -1425,14 +1419,14 @@ document.addEventListener('keydown', function(e) {
|
||||
}
|
||||
|
||||
// Ctrl+N — New entry (before generic guard to prevent browser new window)
|
||||
if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && e.code === 'KeyN' && !isInput && !document.getElementById('addModal').classList.contains('show') && document.getElementById('authSection').classList.contains('hidden')) {
|
||||
if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && (e.key === 'n' || e.key === 'N') && !isInput && !document.getElementById('addModal').classList.contains('show') && document.getElementById('authSection').classList.contains('hidden')) {
|
||||
e.preventDefault();
|
||||
openAdd();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ctrl+T — Toggle trash (before generic guard to prevent browser new tab)
|
||||
if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && e.code === 'KeyT' && !isInput && document.getElementById('authSection').classList.contains('hidden')) {
|
||||
if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && (e.key === 't' || e.key === 'T') && !isInput && document.getElementById('authSection').classList.contains('hidden')) {
|
||||
e.preventDefault();
|
||||
toggleTrash();
|
||||
return;
|
||||
@@ -1440,7 +1434,6 @@ document.addEventListener('keydown', function(e) {
|
||||
|
||||
// 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;
|
||||
|
||||
// Prevent browser defaults for ALL our shortcuts BEFORE dispatching
|
||||
const code = e.code;
|
||||
|
||||
Reference in New Issue
Block a user