@@ -226,7 +226,11 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
226
226
private val input : html.Input =
227
227
val element = document.createElement(" input" ).asInstanceOf [html.Input ]
228
228
element.id = " scaladoc-searchbar-input"
229
- element.addEventListener(" input" , (e) => handleNewQuery(e.target.asInstanceOf [html.Input ].value))
229
+ element.addEventListener(" input" , { e =>
230
+ val inputValue = e.target.asInstanceOf [html.Input ].value
231
+ if inputValue.isEmpty then showHints()
232
+ else handleNewQuery(inputValue)
233
+ })
230
234
element.autocomplete = " off"
231
235
element
232
236
@@ -325,7 +329,7 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
325
329
private def handleEscape () = {
326
330
// clear the search input and close the search
327
331
input.value = " "
328
- handleNewQuery( " " )
332
+ showHints( )
329
333
document.body.removeChild(rootDiv)
330
334
}
331
335
@@ -354,4 +358,59 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
354
358
}
355
359
}
356
360
357
- handleNewQuery(" " )
361
+ private case class ListRoot (elems : Seq [ListNode ])
362
+ private case class ListNode (value : String , nested : ListRoot )
363
+
364
+ private def ul (nodes : ListNode * ) = ListRoot (nodes)
365
+ private def li (s : String ) = ListNode (s, ListRoot (Nil ))
366
+ private def li (s : String , nested : ListRoot ) = ListNode (s, nested)
367
+
368
+ private def renderList : ListRoot => Option [html.UList ] = {
369
+ case ListRoot (Nil ) => None
370
+ case ListRoot (nodes) =>
371
+ val list = document.createElement(" ul" ).asInstanceOf [html.UList ]
372
+ nodes.foreach {
373
+ case ListNode (txt, nested) =>
374
+ val li = document.createElement(" li" ).asInstanceOf [html.LI ]
375
+ li.innerHTML = txt
376
+ renderList(nested).foreach(li.appendChild)
377
+ list.appendChild(li)
378
+ }
379
+ Some (list)
380
+ }
381
+
382
+ private def showHints () = {
383
+ def clearResults () = while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
384
+ val hintsDiv = document.createElement(" div" ).asInstanceOf [html.Div ]
385
+ hintsDiv.classList.add(" searchbar-hints" )
386
+ val icon = document.createElement(" span" ).asInstanceOf [html.Span ]
387
+ icon.classList.add(" fas" )
388
+ icon.classList.add(" fa-lightbulb" )
389
+ icon.classList.add(" fa-5x" )
390
+ val header = document.createElement(" h1" ).asInstanceOf [html.Heading ]
391
+ header.textContent = " A bunch of hints to make your life easier"
392
+ val listElements : ListRoot = ul(
393
+ li(" Type a phrase to search members <b>by name</b> and static sites <b>by title</b>" ),
394
+ li(" Type abbreviations <b>cC, caCa, camCa</b> to search for <b>camelCase</b>" ),
395
+ li(
396
+ " Type a function signature to search for members <b>by signature</b> using Inkuire" ,
397
+ ul(
398
+ li(" Type <b>String => Int</b> to find <b>String.size</b>, <b>String.toInt</b>" ),
399
+ li(" Type <b>String => String => String</b> to find <b>String.mkString</b>, <b>String.stripPrefix</b>" ),
400
+ li(" Inkuire also finds field accessors. Type <b>Some[A] => A</b> to find <b>Some.value</b>" ),
401
+ li(" For more information about Inkuire see <a href=https://docs.scala-lang.org/scala3/guides/scaladoc/search-engine.html>the documentation</a>" ),
402
+ li(" The availability of this function depends on configuration used to generate Scaladoc" )
403
+ )
404
+ )
405
+ )
406
+
407
+ val list = renderList(listElements).get
408
+ list.classList.add(" searchbar-hints-list" )
409
+ hintsDiv.appendChild(icon)
410
+ hintsDiv.appendChild(header)
411
+ hintsDiv.appendChild(list)
412
+ clearResults()
413
+ resultsDiv.appendChild(hintsDiv)
414
+ }
415
+
416
+ showHints()
0 commit comments