diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js index 4c15efde66..15b5d706be 100644 --- a/lib/rdoc/generator/template/darkfish/js/darkfish.js +++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js @@ -76,6 +76,16 @@ function hookSearch() { } search.scrollIntoView = search.scrollInWindow; + + // Check for ?q= URL parameter and trigger search automatically + if (typeof URLSearchParams !== 'undefined') { + var urlParams = new URLSearchParams(window.location.search); + var queryParam = urlParams.get('q'); + if (queryParam) { + input.value = queryParam; + search.search(queryParam, true); + } + } }; function hookFocus() { diff --git a/lib/rdoc/generator/template/darkfish/js/search.js b/lib/rdoc/generator/template/darkfish/js/search.js index d3cded1d57..68e1f77ff8 100644 --- a/lib/rdoc/generator/template/darkfish/js/search.js +++ b/lib/rdoc/generator/template/darkfish/js/search.js @@ -34,6 +34,8 @@ Search.prototype = Object.assign({}, Navigation, new function() { } this.search = function(value, selectFirstMatch) { + this.selectFirstMatch = selectFirstMatch; + value = value.trim().toLowerCase(); if (value) { this.setNavigationActive(true); @@ -76,7 +78,15 @@ Search.prototype = Object.assign({}, Navigation, new function() { //TODO: ECMAScript //if (jQuery.browser.msie) this.$element[0].className += ''; - if (isLast) this.result.setAttribute('aria-busy', 'false'); + if (this.selectFirstMatch && this.current) { + this.selectFirstMatch = false; + this.select(this.current); + } + + if (isLast) { + this.selectFirstMatch = false; + this.result.setAttribute('aria-busy', 'false'); + } } this.move = function(isDown) {