Skip to content

Commit b8fa6d7

Browse files
committed
Review changes
1 parent f117898 commit b8fa6d7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

scaladoc-js/src/searchbar/SearchbarComponent.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.scaladoc
22

33
import org.scalajs.dom._
4+
import org.scalajs.dom.ext._
45
import org.scalajs.dom.html.Input
56
import scala.scalajs.js.timers._
67
import scala.concurrent.duration._
@@ -133,15 +134,12 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
133134
loading.appendChild(animation)
134135
properResultsDiv.appendChild(loading)
135136
inkuireEngine.query(query) { (m: InkuireMatch) =>
136-
var next: Option[Element] = None
137-
0.until(properResultsDiv.children.length).foreach { i =>
138-
val child = properResultsDiv.children(i)
139-
val attr = child.getAttribute("mq")
140-
if attr != null && attr != "" && Integer.parseInt(attr) > m.mq && next.isEmpty then {
141-
next = Some(child)
142-
}
137+
val next = properResultsDiv.children.foldLeft[Option[Element]](None) {
138+
case (acc, child) if !acc.isEmpty => acc
139+
case (_, child) =>
140+
Option.when(child.hasAttribute("mq") && Integer.parseInt(child.getAttribute("mq")) > m.mq)(child)
143141
}
144-
next.fold{
142+
next.fold {
145143
properResultsDiv.appendChild(m.toHTML)
146144
} { next =>
147145
properResultsDiv.insertBefore(m.toHTML, next)

0 commit comments

Comments
 (0)