|
54 | 54 | .find('.filter input')
|
55 | 55 | .on('change', toggleFilter.bind(typeahead))
|
56 | 56 | .prop('checked', window.localStorage.getItem(SEARCH_FILTER_ACTIVE_KEY) === 'true')
|
57 |
| - monitorCtrlKey(input, dropdown) |
| 57 | + monitorCtrlKey.call(typeahead) |
58 | 58 | searchField.addEventListener('click', confineEvent)
|
59 | 59 | document.documentElement.addEventListener('click', clearSearch.bind(typeahead))
|
60 | 60 | document.addEventListener('keydown', handleShortcuts.bind(typeahead))
|
|
125 | 125 | return !query || query !== typeahead.dropdown.datasets[0].query
|
126 | 126 | }
|
127 | 127 |
|
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)) |
131 | 131 | }
|
132 | 132 |
|
133 | 133 | function onCtrlKeyDown (e) {
|
134 | 134 | 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 |
136 | 137 | 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 |
139 | 140 | }
|
140 | 141 |
|
141 | 142 | function onCtrlKeyUp (e) {
|
142 |
| - if (e.keyCode === CTRL_KEY_CODE) this.focus() |
| 143 | + if (e.keyCode !== CTRL_KEY_CODE) return |
| 144 | + this.$input.focus() |
143 | 145 | }
|
144 | 146 |
|
145 | 147 | function onSuggestionMouseDown (e) {
|
|
0 commit comments