Skip to content

Commit b34bee1

Browse files
committed
use custom keyboard shortcut handler to trap "s" and "f"
1 parent d14c6b5 commit b34bee1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/js/vendor/docsearch.bundle.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
activateSearch(require('docsearch.js/dist/cdn/docsearch.js'), document.getElementById('search-script').dataset)
55

6+
var F_KEY = 70
7+
var S_KEY = 83
8+
69
function activateSearch (docsearch, config) {
710
appendStylesheet(config.stylesheet)
811
var algoliaOptions = {
@@ -16,7 +19,7 @@
1619
apiKey: config.apiKey,
1720
indexName: config.indexName,
1821
inputSelector: '#search-query',
19-
autocompleteOptions: { autoselect: true, debug: true, hint: false, keyboardShortcuts: ['s'], minLength: 2 },
22+
autocompleteOptions: { autoselect: true, debug: true, hint: false, keyboardShortcuts: [], minLength: 2 },
2023
algoliaOptions: algoliaOptions,
2124
transformData: transformData,
2225
})
@@ -27,6 +30,7 @@
2730
input.data('aaAutocomplete').dropdown._ensureVisible = ensureVisible
2831
searchForm.addEventListener('click', confineEvent)
2932
document.documentElement.addEventListener('click', resetSearch.bind(autocomplete))
33+
document.documentElement.addEventListener('keydown', handleShortcuts.bind(input))
3034
if (input.attr('autofocus') != null) input.focus()
3135
}
3236

@@ -60,6 +64,15 @@
6064
}
6165
}
6266

67+
function handleShortcuts (e) {
68+
if (e.altKey || e.metaKey || e.ctrlKey || e.shiftKey) return
69+
var keyCode = e.keyCode
70+
if (keyCode === F_KEY || keyCode === S_KEY) {
71+
this.focus()
72+
e.preventDefault()
73+
}
74+
}
75+
6376
function resetSearch () {
6477
this.close()
6578
this.setVal()

0 commit comments

Comments
 (0)