|
79 | 79 | };
|
80 | 80 | var curNavSearch = "";
|
81 | 81 | var curSearchIndex = -1;
|
82 |
| - var imFeelingLucky = false; |
| 82 | + // When true: load the search result indicated by `curSearchIndex`, or the first result if |
| 83 | + // `curSearchIndex` isn't valid. |
| 84 | + var loadSearchResult = false; |
83 | 85 |
|
84 | 86 | // names of modules in the same order as wasm
|
85 | 87 | const moduleList = [];
|
|
696 | 698 | domSearch.value = curNavSearch;
|
697 | 699 | }
|
698 | 700 | render();
|
699 |
| - if (imFeelingLucky) { |
700 |
| - imFeelingLucky = false; |
| 701 | + if (loadSearchResult) { |
| 702 | + loadSearchResult = false; |
701 | 703 | activateSelectedResult();
|
702 | 704 | }
|
703 | 705 | }
|
704 | 706 |
|
| 707 | + function doLoadSearchResult() { |
| 708 | + clearAsyncSearch(); |
| 709 | + loadSearchResult = true; |
| 710 | + const old_hash = location.hash; |
| 711 | + location.hash = computeSearchHash(); |
| 712 | + if (location.hash === old_hash) { |
| 713 | + // With certain sequences of history navigation and input, setting location.hash here |
| 714 | + // causes no change, and the enter key isn't acted on until another modification is made |
| 715 | + // to the search text. Force navigation to work around this. |
| 716 | + navigate(location.hash); |
| 717 | + } |
| 718 | + } |
| 719 | + |
705 | 720 | function activateSelectedResult() {
|
706 | 721 | if (domSectSearchResults.classList.contains("hidden")) {
|
707 | 722 | return;
|
|
720 | 735 | domSearch.blur();
|
721 | 736 | }
|
722 | 737 |
|
| 738 | + function onSearchResultClick(ev) { |
| 739 | + const liDom = ev.target.parentElement; |
| 740 | + const search_index = Array.from(domListSearchResults.children).indexOf(liDom); |
| 741 | + curSearchIndex = search_index; |
| 742 | + doLoadSearchResult(); |
| 743 | + |
| 744 | + ev.preventDefault(); |
| 745 | + ev.stopPropagation(); |
| 746 | + } |
| 747 | + |
723 | 748 | function onSearchKeyDown(ev) {
|
724 | 749 | switch (ev.code) {
|
725 | 750 | case "Enter":
|
726 | 751 | if (ev.shiftKey || ev.ctrlKey || ev.altKey) return;
|
727 | 752 |
|
728 |
| - clearAsyncSearch(); |
729 |
| - imFeelingLucky = true; |
730 |
| - location.hash = computeSearchHash(); |
731 |
| - // With certain sequences of history navigation and input, setting location.hash here |
732 |
| - // causes no change, and the enter key isn't acted on until another modification is made |
733 |
| - // to the search text. Force navigation to work around this. |
734 |
| - navigate(location.hash); |
735 |
| - |
| 753 | + doLoadSearchResult(); |
736 | 754 | ev.preventDefault();
|
737 | 755 | ev.stopPropagation();
|
738 | 756 | return;
|
|
879 | 897 | const full_name = fullyQualifiedName(match);
|
880 | 898 | aDom.textContent = full_name;
|
881 | 899 | aDom.setAttribute('href', navLinkFqn(full_name));
|
| 900 | + aDom.addEventListener("click", onSearchResultClick); |
882 | 901 | }
|
883 | 902 | renderSearchCursor();
|
884 | 903 |
|
|
0 commit comments