Skip to content

Commit d15ae31

Browse files
committed
consolidate arguments to functions that monitor the ctrl key state in search script
1 parent 1906850 commit d15ae31

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/js/vendor/docsearch.bundle.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
.find('.filter input')
5555
.on('change', toggleFilter.bind(typeahead))
5656
.prop('checked', window.localStorage.getItem(SEARCH_FILTER_ACTIVE_KEY) === 'true')
57-
monitorCtrlKey(input, dropdown)
57+
monitorCtrlKey.call(typeahead)
5858
searchField.addEventListener('click', confineEvent)
5959
document.documentElement.addEventListener('click', clearSearch.bind(typeahead))
6060
document.addEventListener('keydown', handleShortcuts.bind(typeahead))
@@ -125,21 +125,23 @@
125125
return !query || query !== typeahead.dropdown.datasets[0].query
126126
}
127127

128-
function monitorCtrlKey (input, dropdown) {
129-
input.on('keydown', onCtrlKeyDown.bind(dropdown))
130-
dropdown.$container.on('keyup', onCtrlKeyUp.bind(input))
128+
function monitorCtrlKey () {
129+
this.$input.on('keydown', onCtrlKeyDown.bind(this))
130+
this.dropdown.$container.on('keyup', onCtrlKeyUp.bind(this))
131131
}
132132

133133
function onCtrlKeyDown (e) {
134134
if (e.keyCode !== CTRL_KEY_CODE) return
135-
var container = this.datasets[0].$el
135+
var dropdown = this.dropdown
136+
var container = dropdown.datasets[0].$el
136137
var prevScrollTop = container.scrollTop()
137-
this.getCurrentCursor().find('a').focus() // calling focus can cause the container to scroll
138-
container.scrollTop(prevScrollTop)
138+
dropdown.getCurrentCursor().find('a').focus()
139+
container.scrollTop(prevScrollTop) // calling focus can cause the container to scroll, so restore it
139140
}
140141

141142
function onCtrlKeyUp (e) {
142-
if (e.keyCode === CTRL_KEY_CODE) this.focus()
143+
if (e.keyCode !== CTRL_KEY_CODE) return
144+
this.$input.focus()
143145
}
144146

145147
function onSuggestionMouseDown (e) {

0 commit comments

Comments
 (0)