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. * 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; const text = ev.target.value;
// If no input clear all. // If no input clear all.
@ -101,11 +101,20 @@ function handleSearch(dataCenter, err, ev, sr, maxResults) {
// update autocomplete results // update autocomplete results
removeAllChildren(sr); removeAllChildren(sr);
for (const { name, docLink } of result) { for (const { name, doc, docLink } of result) {
const d = sr.appendChild(document.createElement("a")); const row = sr.appendChild(document.createElement("div"));
d.innerText = name; row.classList.add("search_result")
d.title = name; const linkdiv = row.appendChild(document.createElement("div"))
d.href = SITE_ROOT + docLink; 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 // handle error
@ -122,13 +131,13 @@ DeclarationDataCenter.init()
// Search autocompletion. // Search autocompletion.
SEARCH_INPUT.addEventListener("input", ev => handleSearch(dataCenter, null, ev, ac_results, AC_MAX_RESULTS)); SEARCH_INPUT.addEventListener("input", ev => handleSearch(dataCenter, null, ev, ac_results, AC_MAX_RESULTS));
if(SEARCH_PAGE_INPUT) { 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")) SEARCH_PAGE_INPUT.dispatchEvent(new Event("input"))
} }
}) })
.catch(e => { .catch(e => {
SEARCH_INPUT.addEventListener("input", ev => handleSearch(null, e, ev, ac_results, AC_MAX_RESULTS)); SEARCH_INPUT.addEventListener("input", ev => handleSearch(null, e, ev, ac_results, AC_MAX_RESULTS));
if(SEARCH_PAGE_INPUT) { 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; padding-left: 0.5ex;
cursor: pointer; cursor: pointer;
} }
#autocomplete_results .selected { #autocomplete_results .selected {
background: white; background: white;
border-color: #f0a202; border-color: #f0a202;
@ -211,6 +212,27 @@ header header_filename {
font-style: italic; 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 { main, nav {
margin-top: calc(var(--header-height) + 1em); 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, .imports li, code, .decl_header, .attributes, .structure_field_info,
.constructor, .instances li, .equation, #autocomplete_results div, .constructor, .instances li, .equation, .result_link, .structure_ext_ctor {
.structure_ext_ctor {
font-family: 'Source Code Pro', monospace; font-family: 'Source Code Pro', monospace;
} }