Skip to content

Commit 74898d2

Browse files
committed
only move cursor in search results on mouse down instead of mouse enter; underline title at cursor
1 parent 3435898 commit 74898d2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/css/vendor/docsearch.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
font-weight: var(--body-font-weight-bold);
3737
}
3838

39+
.algolia-autocomplete .algolia-docsearch-suggestion:hover .algolia-docsearch-suggestion--title,
40+
.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--title {
41+
text-decoration: underline;
42+
}
43+
3944
.algolia-autocomplete .algolia-docsearch-suggestion .algolia-docsearch-suggestion--subcategory-column {
4045
font-weight: normal;
4146
}

src/js/vendor/docsearch.bundle.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@
3636
var autocomplete = input.autocomplete
3737
var typeahead = input.data('aaAutocomplete')
3838
var dropdown = typeahead.dropdown
39+
var menu = dropdown.$menu
3940
autocomplete.setVal() // clear value on page reload
4041
input.on('autocomplete:closed', clearSearch.bind(autocomplete))
4142
input.on('autocomplete:selected', disableClose)
4243
input.on('autocomplete:updated', resetScroll.bind(autocomplete.getWrapper().firstChild))
4344
dropdown._ensureVisible = ensureVisible
45+
menu.off('mousedown.aa')
46+
var suggestionSelector = '.' + dropdown.cssClasses.prefix + dropdown.cssClasses.suggestion
47+
menu.on('mousedown.aa', suggestionSelector, onSuggestionMouseDown.bind(dropdown))
48+
menu.off('mouseenter.aa')
49+
menu.off('mouseleave.aa')
4450
if (filterInput) filterInput.addEventListener('change', toggleFilter.bind(typeahead))
4551
monitorCtrlKey(input, dropdown)
4652
searchField.addEventListener('click', confineEvent)
@@ -105,13 +111,29 @@
105111
}
106112

107113
function onCtrlKeyDown (e) {
108-
if (e.keyCode === CTRL_KEY) this.getCurrentCursor().find('a').focus()
114+
if (e.keyCode !== CTRL_KEY) return
115+
var container = this.datasets[0].$el
116+
var prevScrollTop = container.scrollTop()
117+
this.getCurrentCursor().find('a').focus() // calling focus can cause the container to scroll
118+
container.scrollTop(prevScrollTop)
109119
}
110120

111121
function onCtrlKeyUp (e) {
112122
if (e.keyCode === CTRL_KEY) this.focus()
113123
}
114124

125+
function onSuggestionMouseDown (e) {
126+
var dropdown = this
127+
var suggestion = dropdown
128+
._getSuggestions()
129+
.filter('#' + e.currentTarget.id)
130+
if (suggestion.attr('id') === dropdown._getCursor().attr('id')) return
131+
dropdown._removeCursor()
132+
setTimeout(function () {
133+
dropdown._setCursor(suggestion, false)
134+
}, 0)
135+
}
136+
115137
function clearSearch () {
116138
this.close()
117139
this.setVal()

0 commit comments

Comments
 (0)