|
116 | 116 | } |
117 | 117 |
|
118 | 118 | function toggleFilter (e) { |
119 | | - this.$input.focus() |
| 119 | + if ('restoring' in this.dropdown) return |
120 | 120 | window.localStorage.setItem(SEARCH_FILTER_ACTIVE_KEY, e.target.checked) |
121 | | - if (isClosed(this)) return |
122 | | - var dropdown = this.dropdown |
123 | | - dropdown.update(this.getVal()) |
| 121 | + isClosed(this) ? this.$input.focus() : requery.call(this) |
124 | 122 | } |
125 | 123 |
|
126 | 124 | function confineEvent (e) { |
|
146 | 144 |
|
147 | 145 | function handleShortcuts (e) { |
148 | 146 | var target = e.target || {} |
149 | | - if (e.ctrlKey && e.keyCode === LT_KEY_CODE && target === this.$input[0]) { |
150 | | - restoreSearch.call(this) |
151 | | - return |
152 | | - } |
| 147 | + if (e.ctrlKey && e.keyCode === LT_KEY_CODE && target === this.$input[0]) return restoreSearch.call(this) |
153 | 148 | if (e.altKey || e.shiftKey || target.isContentEditable || 'disabled' in target) return |
154 | 149 | if (e.ctrlKey ? e.keyCode === SOLIDUS_KEY_CODE : e.keyCode === S_KEY_CODE) { |
155 | 150 | this.$input.focus() |
|
208 | 203 | delete this.ctrlKeyDown |
209 | 204 | } |
210 | 205 |
|
| 206 | + function requery (query) { |
| 207 | + this.$input.focus() |
| 208 | + query === undefined ? (query = this.input.getInputValue()) : this.input.setInputValue(query, true) |
| 209 | + this.input.setQuery(query) |
| 210 | + this.dropdown.update(query) |
| 211 | + } |
| 212 | + |
211 | 213 | // preserves the original order of results by qualifying unique occurrences of the same lvl0 and lvl1 values |
212 | 214 | function protectHitOrder (hits) { |
213 | 215 | var prevLvl0 |
|
244 | 246 | function restoreSearch () { |
245 | 247 | var searchState = readSavedSearchState() |
246 | 248 | if (!searchState) return |
247 | | - this.setVal() |
248 | | - this.$facetFilterInput.prop('checked', searchState.filter) |
249 | | - var dropdown = this.dropdown |
250 | | - dropdown.restoring = searchState |
251 | | - this.$input.focus() |
252 | | - this.setVal(searchState.query) // cursor is restored by onResultsUpdated => |
| 249 | + this.dropdown.restoring = searchState |
| 250 | + this.$facetFilterInput.prop('checked', searchState.filter) // change event will be ignored |
| 251 | + requery.call(this, searchState.query) // cursor is restored by onResultsUpdated => |
253 | 252 | } |
254 | 253 |
|
255 | 254 | function saveSearchState () { |
|
0 commit comments