(center: boolean)
| 309 | } |
| 310 | |
| 311 | function scrollToSelection(center: boolean) { |
| 312 | if (!scroll) return |
| 313 | let remaining = store.selected |
| 314 | let index = 0 |
| 315 | // Locate the row by position because a unique renderable ID cannot currently be ensured. |
| 316 | for (const [category, options] of grouped()) { |
| 317 | if (category) index++ |
| 318 | if (remaining < options.length) { |
| 319 | index += remaining |
| 320 | break |
| 321 | } |
| 322 | index += options.length |
| 323 | remaining -= options.length |
| 324 | } |
| 325 | const target = scroll.getChildren()[index] |
| 326 | if (!target) return |
| 327 | const y = target.y - scroll.y |
| 328 | if (center) { |
| 329 | const centerOffset = Math.floor(scroll.height / 2) |
| 330 | scroll.scrollBy(y - centerOffset) |
| 331 | } else { |
| 332 | if (y >= scroll.height) { |
| 333 | scroll.scrollBy(y - scroll.height + 1) |
| 334 | } |
| 335 | if (y < 0) { |
| 336 | scroll.scrollBy(y) |
| 337 | if (isDeepEqual(flat()[0].value, selected()?.value)) { |
| 338 | scroll.scrollTo(0) |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | function submit() { |
| 345 | if (props.locked) return |
no test coverage detected