From 03c20fcb8cbdbd73380a6c24921023362c7a825b Mon Sep 17 00:00:00 2001 From: Zaki <18zaki18@gmail.com> Date: Sat, 9 May 2026 19:22:15 +0100 Subject: [PATCH] Fix Ctrl+N/T opening browser windows instead of app actions Moved Ctrl+N and Ctrl+T handlers before the generic Ctrl guard with their own e.preventDefault() and early return, matching the pattern used for Ctrl+A. Removed them from the old else-if chain and combined preventDefault block. --- js/app.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/js/app.js b/js/app.js index 3c323ae..0d08865 100644 --- a/js/app.js +++ b/js/app.js @@ -1417,15 +1417,29 @@ document.addEventListener('keydown', function(e) { return; } + // 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')) { + 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')) { + e.preventDefault(); + toggleTrash(); + return; + } + // Only handle Ctrl+[key], no Shift/Alt/Meta if (!e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return; // Prevent browser defaults for ALL our shortcuts BEFORE dispatching const code = e.code; - if (code === 'KeyN' || code === 'KeyF' || code === 'KeyT' || code === 'KeyL' || code === 'KeyS') { + if (code === 'KeyF' || code === 'KeyL' || code === 'KeyS') { e.preventDefault(); } - + if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && (e.key === 'a' || e.key === 'A') && !isInput && document.getElementById('authSection').classList.contains('hidden')) { e.preventDefault(); getFilteredEntries(view === 'grouped' || view === 'detail').forEach(e => selectedIds.add(e.id)); @@ -1435,13 +1449,9 @@ document.addEventListener('keydown', function(e) { return; } - if (code === 'KeyN') { - if (!isInput && !document.getElementById('addModal').classList.contains('show')) openAdd(); - } else if (code === 'KeyF') { + if (code === 'KeyF') { const el = document.getElementById('searchInput'); if (el) { el.focus(); el.select(); } - } else if (code === 'KeyT') { - if (!isInput) toggleTrash(); } else if (code === 'KeyL') { if (!isInput) doLogout(); } else if (code === 'KeyS') {