Add definition doc string to search result page.

Adds a two-column table to the search results so you can see the doc string next to
the result.  The doc string is not parsed/converted to markdown yet, but that could
be done later.
main
Jeremy Salwen 2023-01-25 20:09:47 -05:00 committed by Henrik Böving
parent 033003c6cb
commit 1575eeedd2
2 changed files with 40 additions and 10 deletions

View File

@ -80,7 +80,7 @@ function removeAllChildren(node) {
/**
* Handle user input and perform search.
*/
function handleSearch(dataCenter, err, ev, sr, maxResults) {
function handleSearch(dataCenter, err, ev, sr, maxResults, includedoc=false) {
const text = ev.target.value;
// If no input clear all.
@ -101,11 +101,20 @@ function handleSearch(dataCenter, err, ev, sr, maxResults) {
// update autocomplete results
removeAllChildren(sr);
for (const { name, docLink } of result) {
const d = sr.appendChild(document.createElement("a"));
d.innerText = name;
d.title = name;
d.href = SITE_ROOT + docLink;
for (const { name, doc, docLink } of result) {
const row = sr.appendChild(document.createElement("div"));
row.classList.add("search_result")
const linkdiv = row.appendChild(document.createElement("div"))
linkdiv.classList.add("result_link")
const link = linkdiv.appendChild(document.createElement("a"));
link.innerText = name;
link.title = name;
link.href = SITE_ROOT + docLink;
if (includedoc) {
const doctext = row.appendChild(document.createElement("div"));
doctext.innerText = doc
doctext.classList.add("result_doc")
}
}
}
// handle error
@ -122,13 +131,13 @@ DeclarationDataCenter.init()
// Search autocompletion.
SEARCH_INPUT.addEventListener("input", ev => handleSearch(dataCenter, null, ev, ac_results, AC_MAX_RESULTS));
if(SEARCH_PAGE_INPUT) {
SEARCH_PAGE_INPUT.addEventListener("input", ev => handleSearch(dataCenter, null, ev, SEARCH_RESULTS, SEARCH_PAGE_MAX_RESULTS))
SEARCH_PAGE_INPUT.addEventListener("input", ev => handleSearch(dataCenter, null, ev, SEARCH_RESULTS, SEARCH_PAGE_MAX_RESULTS, true))
SEARCH_PAGE_INPUT.dispatchEvent(new Event("input"))
}
})
.catch(e => {
SEARCH_INPUT.addEventListener("input", ev => handleSearch(null, e, ev, ac_results, AC_MAX_RESULTS));
if(SEARCH_PAGE_INPUT) {
SEARCH_PAGE_INPUT.addEventListener("input", ev => handleSearch(null, e, ev, SEARCH_RESULTS, SEARCH_PAGE_MAX_RESULTS));
SEARCH_PAGE_INPUT.addEventListener("input", ev => handleSearch(null, e, ev, SEARCH_RESULTS, SEARCH_PAGE_MAX_RESULTS, true));
}
});

View File

@ -197,6 +197,7 @@ header header_filename {
padding-left: 0.5ex;
cursor: pointer;
}
#autocomplete_results .selected {
background: white;
border-color: #f0a202;
@ -211,6 +212,27 @@ header header_filename {
font-style: italic;
}
#search_results {
width: 100%;
display: table;
table-layout: auto;
}
.search_result {
width: 100%;
display: table-row;
}
.result_link, .result_doc {
display: table-cell;
overflow: hidden;
}
#search_results .result_link, #search_results .result_doc {
display: table-cell;
overflow: hidden;
border-bottom: 1px solid rgba(0, 0, 0, 0.8);
}
main, nav {
margin-top: calc(var(--header-height) + 1em);
}
@ -485,8 +507,7 @@ main h2, main h3, main h4, main h5, main h6 {
}
.imports li, code, .decl_header, .attributes, .structure_field_info,
.constructor, .instances li, .equation, #autocomplete_results div,
.structure_ext_ctor {
.constructor, .instances li, .equation, .result_link, .structure_ext_ctor {
font-family: 'Source Code Pro', monospace;
}