add vim-like keybind to search

This commit is contained in:
Will Lewis Williams 2022-05-31 12:28:36 +01:00
parent 016effe3d8
commit b8727deb0d

View File

@ -23,6 +23,19 @@ document.addEventListener('DOMContentLoaded', () => {
const search = document.querySelector('#search')
const clearSearch = document.querySelector('.clear-search')
const artlist = document.getElementById('artlist')
document.addEventListener('keydown', function(e) {
// if search already focused do nothing
if (search === document.activeElement) return;
// if key pressed is '/'
if (e.keyCode === 191) {
search.focus();
// preventDefault so '/' is not added to search value
e.preventDefault();
}
})
search.addEventListener('input', e => {
// grab search input value