Skip to content

Commit 9c78605

Browse files
authored
resolves #100 add support for Ctrl+Enter in search results (PR #101)
1 parent 7a430dd commit 9c78605

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/css/header.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ body {
8383
flex: auto;
8484
}
8585

86-
#search .query:focus {
86+
#search :focus {
8787
outline: none;
8888
}
8989

src/js/vendor/docsearch.bundle.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

6+
var CTRL_KEY = 17
67
var S_KEY = 83
78
var SOLIDUS_KEY = 191
89

@@ -39,6 +40,7 @@
3940
input.on('autocomplete:updated', resetScroll.bind(autocomplete.getWrapper().firstChild))
4041
typeahead.dropdown._ensureVisible = ensureVisible
4142
if (filterInput) filterInput.addEventListener('change', toggleFilter.bind(typeahead))
43+
monitorCtrlKey(input, typeahead.dropdown.$menu)
4244
searchField.addEventListener('click', confineEvent)
4345
document.documentElement.addEventListener('click', resetSearch.bind(autocomplete))
4446
document.addEventListener('keydown', handleShortcuts.bind(input))
@@ -98,6 +100,19 @@
98100
}
99101
}
100102

103+
function monitorCtrlKey (input, dropdown) {
104+
input.on('keydown', onCtrlKeyDown.bind(dropdown))
105+
dropdown.on('keyup', onCtrlKeyUp.bind(input))
106+
}
107+
108+
function onCtrlKeyDown (e) {
109+
if (e.keyCode === CTRL_KEY) this.find('.ds-cursor a').focus()
110+
}
111+
112+
function onCtrlKeyUp (e) {
113+
if (e.keyCode === CTRL_KEY) this.focus()
114+
}
115+
101116
function resetSearch () {
102117
this.close()
103118
this.setVal()

0 commit comments

Comments
 (0)