Allow Cmd/Ctrl+K for search, remove 's'
This commit is contained in:
+11
-17
@@ -34,13 +34,15 @@ import Fuse from '{{ "fuse.min.mjs" | relURL }}'
|
|||||||
input.addEventListener('focus', init);
|
input.addEventListener('focus', init);
|
||||||
input.addEventListener('keyup', search);
|
input.addEventListener('keyup', search);
|
||||||
|
|
||||||
document.addEventListener('keypress', focusSearchFieldOnKeyPress);
|
document.addEventListener('keydown', focusOnKeyDown);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Event} event
|
* @param {KeyboardEvent} event
|
||||||
*/
|
*/
|
||||||
function focusSearchFieldOnKeyPress(event) {
|
function focusOnKeyDown(event) {
|
||||||
if (event.target.value !== undefined) {
|
if (event.key === 'k' && (event.metaKey || event.ctrlKey)) {
|
||||||
|
event.preventDefault();
|
||||||
|
input.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,22 +50,14 @@ import Fuse from '{{ "fuse.min.mjs" | relURL }}'
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const characterPressed = String.fromCharCode(event.charCode);
|
if (event.target.value !== undefined) {
|
||||||
if (!isHotkey(characterPressed)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.focus();
|
if (event.key === '/') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
input.focus();
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param {String} character
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
function isHotkey(character) {
|
|
||||||
const dataHotkeys = input.getAttribute('data-hotkeys') || '';
|
|
||||||
return dataHotkeys.indexOf(character) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<input id="book-search-input" type="text"
|
<input id="book-search-input" type="text"
|
||||||
placeholder="{{ partial "docs/text/i18n" "Search" }}"
|
placeholder="{{ partial "docs/text/i18n" "Search" }}"
|
||||||
aria-label="{{ partial "docs/text/i18n" "Search" }}"
|
aria-label="{{ partial "docs/text/i18n" "Search" }}"
|
||||||
maxlength="64" data-hotkeys="s/" />
|
maxlength="64" />
|
||||||
<div class="book-search-spinner hidden"></div>
|
<div class="book-search-spinner hidden"></div>
|
||||||
<ul id="book-search-results"></ul>
|
<ul id="book-search-results"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user