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 = {
2121 section : 'section'
2222}
2323
24+ const DEFAULT_AUTOCOMPLETE_LIMIT = 10
25+
2426/**
2527 * Returns a list of autocomplete suggestion objects matching the given term.
2628 *
2729 * @param {String } query The query string to search for.
2830 * @param {Number } limit The maximum number of results to return.
2931 * @returns {Suggestion[] } List of suggestions sorted and limited.
3032 */
31- export function getSuggestions ( query , limit = 8 ) {
33+ export function getSuggestions ( query , explicitLimit = null ) {
34+ const limit = explicitLimit || window . autocompleteLimit || DEFAULT_AUTOCOMPLETE_LIMIT
3235 if ( isBlank ( query ) ) {
3336 return [ ]
3437 }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ if (!isEmbedded) {
2626
2727function initialize ( ) {
2828 addEventListeners ( )
29+ setAutocompleteLimit ( )
2930
3031 window . onTogglePreviewClick = function ( event , open ) {
3132 event . preventDefault ( )
@@ -59,6 +60,15 @@ export function focusSearchInput () {
5960 searchInput . focus ( )
6061}
6162
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+
6272function addEventListeners ( ) {
6373 const searchInput = qs ( SEARCH_INPUT_SELECTOR )
6474
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ describe('getSuggestions', () => {
123123 } )
124124
125125 it ( 'returns max 8 results' , ( ) => {
126- expect ( getSuggestions ( 'e' ) . length ) . to . eql ( 8 )
126+ expect ( getSuggestions ( 'e' ) . length ) . to . eql ( 10 )
127127 } )
128128
129129 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
365365
366366 * `exdoc:autocomplete` - when set to "off", it disables autocompletion.
367367
368+ * `exdoc:autocomplete-limit` - Set to an integer to configure how many results
369+ appear in the autocomplete dropdown. Defaults to 10.
370+
368371 * `exdoc:full-text-search-url` - the URL to use when performing full text
369372 search. The search string will be appended to the URL as an encoded
370373 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