Skip to content

Commit 00dc084

Browse files
committed
search: initialize the results URL earlier
When a person types really fast into the search box and also hits the Enter key really quickly after that, the current code directs the browser to https://git-scm.com/undefined. The reason? At that stage, the search results had not yet been retrieved and as a consequence, the list of results to be shown in the live search were not populated. But that's exactly from where this URL was obtained. Let's just initialize that URL a lot earlier. This fixes git#2030 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e47af0e commit 00dc084

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

assets/js/application.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ var Search = {
244244

245245
if(term != Search.currentSearch) {
246246
Search.currentSearch = term;
247+
const language = document.querySelector("html")?.getAttribute("lang");
248+
const allResultsURL = `${baseURLPrefix}search/results?search=${term}${language && `&language=${language}`}`;
247249
$("#search-results").html(`
248250
<header> Search Results </header>
249251
<table>
@@ -253,7 +255,9 @@ var Search = {
253255
<td class="matches">
254256
<ul>
255257
<li>
256-
<a class="highlight" id="show-results-label">Searching for <span id="search-term">&nbsp;</span>...</a>
258+
<a class="highlight" id="show-results-label" href="${allResultsURL}">
259+
Searching for <span id="search-term">&nbsp;</span>...
260+
</a>
257261
</li>
258262
</ul>
259263
</td>
@@ -288,11 +292,8 @@ var Search = {
288292
$("#show-results-label").text("No matching pages found.");
289293
return;
290294
}
291-
292-
const language = document.querySelector("html")?.getAttribute("lang");
293295
$("#show-results-label")
294296
.text("Show all results...")
295-
.attr('href', `${baseURLPrefix}search/results?search=${term}${language && `&language=${language}`}`);
296297

297298
const loadButton = $("#load-more-results");
298299
loadButton.text(`Loading ${

0 commit comments

Comments
 (0)