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.
This commit is contained in:
@@ -1417,12 +1417,26 @@ document.addEventListener('keydown', function(e) {
|
|||||||
return;
|
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
|
// 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
|
// Prevent browser defaults for ALL our shortcuts BEFORE dispatching
|
||||||
const code = e.code;
|
const code = e.code;
|
||||||
if (code === 'KeyN' || code === 'KeyF' || code === 'KeyT' || code === 'KeyL' || code === 'KeyS') {
|
if (code === 'KeyF' || code === 'KeyL' || code === 'KeyS') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1435,13 +1449,9 @@ document.addEventListener('keydown', function(e) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code === 'KeyN') {
|
if (code === 'KeyF') {
|
||||||
if (!isInput && !document.getElementById('addModal').classList.contains('show')) openAdd();
|
|
||||||
} else if (code === 'KeyF') {
|
|
||||||
const el = document.getElementById('searchInput');
|
const el = document.getElementById('searchInput');
|
||||||
if (el) { el.focus(); el.select(); }
|
if (el) { el.focus(); el.select(); }
|
||||||
} else if (code === 'KeyT') {
|
|
||||||
if (!isInput) toggleTrash();
|
|
||||||
} else if (code === 'KeyL') {
|
} else if (code === 'KeyL') {
|
||||||
if (!isInput) doLogout();
|
if (!isInput) doLogout();
|
||||||
} else if (code === 'KeyS') {
|
} else if (code === 'KeyS') {
|
||||||
|
|||||||
Reference in New Issue
Block a user