File tree Expand file tree Collapse file tree 4 files changed +18
-2
lines changed Expand file tree Collapse file tree 4 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -21,14 +21,17 @@ const SUGGESTION_CATEGORY = {
21
21
section : 'section'
22
22
}
23
23
24
+ const DEFAULT_AUTOCOMPLETE_LIMIT = 10
25
+
24
26
/**
25
27
* Returns a list of autocomplete suggestion objects matching the given term.
26
28
*
27
29
* @param {String } query The query string to search for.
28
30
* @param {Number } limit The maximum number of results to return.
29
31
* @returns {Suggestion[] } List of suggestions sorted and limited.
30
32
*/
31
- export function getSuggestions ( query , limit = 8 ) {
33
+ export function getSuggestions ( query , explicitLimit = null ) {
34
+ const limit = explicitLimit || window . autocompleteLimit || DEFAULT_AUTOCOMPLETE_LIMIT || 10
32
35
if ( isBlank ( query ) ) {
33
36
return [ ]
34
37
}
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ if (!isEmbedded) {
26
26
27
27
function initialize ( ) {
28
28
addEventListeners ( )
29
+ setAutocompleteLimit ( )
29
30
30
31
window . onTogglePreviewClick = function ( event , open ) {
31
32
event . preventDefault ( )
@@ -59,6 +60,15 @@ export function focusSearchInput () {
59
60
searchInput . focus ( )
60
61
}
61
62
63
+ function setAutocompleteLimit ( ) {
64
+ const searchInput = qs ( SEARCH_INPUT_SELECTOR )
65
+ const autocompleteLimit = parseInt ( document . querySelector ( 'meta[name="exdoc:autocomplete-limit"]' ) . content )
66
+ if ( autocompleteLimit ) {
67
+ window . autocompleteLimit = autocompleteLimit
68
+ }
69
+ searchInput . setAttribute ( 'autocomplete-limit' , autocompleteLimit )
70
+ }
71
+
62
72
function addEventListeners ( ) {
63
73
const searchInput = qs ( SEARCH_INPUT_SELECTOR )
64
74
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ describe('getSuggestions', () => {
123
123
} )
124
124
125
125
it ( 'returns max 8 results' , ( ) => {
126
- expect ( getSuggestions ( 'e' ) . length ) . to . eql ( 8 )
126
+ expect ( getSuggestions ( 'e' ) . length ) . to . eql ( 10 )
127
127
} )
128
128
129
129
it ( 'returns no results if no match found' , ( ) => {
Original file line number Diff line number Diff line change @@ -365,6 +365,9 @@ defmodule Mix.Tasks.Docs do
365
365
366
366
* `exdoc:autocomplete` - when set to "off", it disables autocompletion.
367
367
368
+ * `exdoc:autocomplete-limit` - Set to an integer to configure how many results
369
+ appear in the autocomplete dropdown. Defaults to 10.
370
+
368
371
* `exdoc:full-text-search-url` - the URL to use when performing full text
369
372
search. The search string will be appended to the URL as an encoded
370
373
parameter. You could use this to bring a custom search engine to your
You can’t perform that action at this time.
0 commit comments