@@ -234,7 +234,11 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
234234 private val input : html.Input =
235235 val element = document.createElement(" input" ).asInstanceOf [html.Input ]
236236 element.id = " scaladoc-searchbar-input"
237- element.addEventListener(" input" , (e) => handleNewQuery(e.target.asInstanceOf [html.Input ].value))
237+ element.addEventListener(" input" , { e =>
238+ val inputValue = e.target.asInstanceOf [html.Input ].value
239+ if inputValue.isEmpty then showHints()
240+ else handleNewQuery(inputValue)
241+ })
238242 element.autocomplete = " off"
239243 element
240244
@@ -333,7 +337,7 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
333337 private def handleEscape () = {
334338 // clear the search input and close the search
335339 input.value = " "
336- handleNewQuery( " " )
340+ showHints( )
337341 document.body.removeChild(rootDiv)
338342 }
339343
@@ -362,4 +366,59 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
362366 }
363367 }
364368
365- handleNewQuery(" " )
369+ private case class ListRoot (elems : Seq [ListNode ])
370+ private case class ListNode (value : String , nested : ListRoot )
371+
372+ private def ul (nodes : ListNode * ) = ListRoot (nodes)
373+ private def li (s : String ) = ListNode (s, ListRoot (Nil ))
374+ private def li (s : String , nested : ListRoot ) = ListNode (s, nested)
375+
376+ private def renderList : ListRoot => Option [html.UList ] = {
377+ case ListRoot (Nil ) => None
378+ case ListRoot (nodes) =>
379+ val list = document.createElement(" ul" ).asInstanceOf [html.UList ]
380+ nodes.foreach {
381+ case ListNode (txt, nested) =>
382+ val li = document.createElement(" li" ).asInstanceOf [html.LI ]
383+ li.innerHTML = txt
384+ renderList(nested).foreach(li.appendChild)
385+ list.appendChild(li)
386+ }
387+ Some (list)
388+ }
389+
390+ private def showHints () = {
391+ def clearResults () = while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
392+ val hintsDiv = document.createElement(" div" ).asInstanceOf [html.Div ]
393+ hintsDiv.classList.add(" searchbar-hints" )
394+ val icon = document.createElement(" span" ).asInstanceOf [html.Span ]
395+ icon.classList.add(" fas" )
396+ icon.classList.add(" fa-lightbulb" )
397+ icon.classList.add(" fa-5x" )
398+ val header = document.createElement(" h1" ).asInstanceOf [html.Heading ]
399+ header.textContent = " A bunch of hints to make your life easier"
400+ val listElements : ListRoot = ul(
401+ li(" Type a phrase to search members <b>by name</b> and static sites <b>by title</b>" ),
402+ li(" Type abbreviations <b>cC, caCa, camCa</b> to search for <b>camelCase</b>" ),
403+ li(
404+ " Type a function signature to search for members <b>by signature</b> using Inkuire" ,
405+ ul(
406+ li(" Type <b>String => Int</b> to find <b>String.size</b>, <b>String.toInt</b>" ),
407+ li(" Type <b>String => String => String</b> to find <b>String.mkString</b>, <b>String.stripPrefix</b>" ),
408+ li(" Inkuire also finds field accessors. Type <b>Some[A] => A</b> to find <b>Some.value</b>" ),
409+ li(" For more information about Inkuire see <a href=https://docs.scala-lang.org/scala3/guides/scaladoc/search-engine.html>the documentation</a>" ),
410+ li(" The availability of this function depends on configuration used to generate Scaladoc" )
411+ )
412+ )
413+ )
414+
415+ val list = renderList(listElements).get
416+ list.classList.add(" searchbar-hints-list" )
417+ hintsDiv.appendChild(icon)
418+ hintsDiv.appendChild(header)
419+ hintsDiv.appendChild(list)
420+ clearResults()
421+ resultsDiv.appendChild(hintsDiv)
422+ }
423+
424+ showHints()
0 commit comments