mirror of
https://github.com/FuzzyGrim/Yamtrack.git
synced 2026-03-03 00:27:02 +00:00
add keyboard shortcut to focus search bar #891
This commit is contained in:
19
src/static/js/searchShortcut.js
Normal file
19
src/static/js/searchShortcut.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// Global keyboard shortcut for search
|
||||
document.addEventListener('keydown', (e) => {
|
||||
// Ignore if typing in an input, textarea, or contenteditable
|
||||
const activeEl = document.activeElement;
|
||||
const isTyping = activeEl.tagName === 'INPUT' ||
|
||||
activeEl.tagName === 'TEXTAREA' ||
|
||||
activeEl.isContentEditable;
|
||||
|
||||
if (isTyping) return;
|
||||
|
||||
if (e.key === '/') {
|
||||
e.preventDefault();
|
||||
const searchInput = document.getElementById('global-search');
|
||||
if (searchInput) {
|
||||
searchInput.focus();
|
||||
searchInput.select();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -225,6 +225,7 @@
|
||||
<div class="relative grow">
|
||||
{# Search input #}
|
||||
<input type="search"
|
||||
id="global-search"
|
||||
name="q"
|
||||
value="{{ request.GET.q }}"
|
||||
:placeholder="getPlaceholder()"
|
||||
@@ -339,5 +340,6 @@
|
||||
</script>
|
||||
|
||||
<script src="{% static 'js/mediaStatusDateHandler.js' %}{% get_static_file_mtime 'js/mediaStatusDateHandler.js' %}"></script>
|
||||
<script src="{% static 'js/searchShortcut.js' %}{% get_static_file_mtime 'js/searchShortcut.js' %}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user