diff --git a/src/main/kotlin/org/janelia/saalfeldlab/fx/extensions/ListViewExtensions.kt b/src/main/kotlin/org/janelia/saalfeldlab/fx/extensions/ListViewExtensions.kt index 4b9fcb1..3d1a94d 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/fx/extensions/ListViewExtensions.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/fx/extensions/ListViewExtensions.kt @@ -11,7 +11,7 @@ fun ListView<*>.bindHeightToItemSize() { val defaultMaxRows = 18 val cellHeightFallBack = 24.0 val prefHeightBinding: ObjectBinding = items.createObservableBinding { - val cellHeight = (lookup(".list-cell") as? ListCell<*>)?.height ?: cellHeightFallBack + val cellHeight = (lookup(".list-cell") as? ListCell<*>)?.height?.let { h -> if (h == 0.0) cellHeightFallBack else h } ?: cellHeightFallBack val borderPadding = padding.top + padding.bottom borderPadding + cellHeight * it.size.coerceAtMost(defaultMaxRows) } diff --git a/src/main/kotlin/org/janelia/saalfeldlab/fx/ui/MatchSelection.kt b/src/main/kotlin/org/janelia/saalfeldlab/fx/ui/MatchSelection.kt index 1034e48..253f49f 100644 --- a/src/main/kotlin/org/janelia/saalfeldlab/fx/ui/MatchSelection.kt +++ b/src/main/kotlin/org/janelia/saalfeldlab/fx/ui/MatchSelection.kt @@ -99,16 +99,8 @@ class MatchSelection( fuzzySearchField.requestFocus() fuzzySearchField.selectEnd() } - val currentOrder = FXCollections.observableArrayList() - fuzzySearchField.textProperty().addListener { _, _, fuzzyFilter -> - val matches = when (emptyBehavior) { - EmptyBehavior.MATCH_ALL -> if (fuzzyFilter == null || fuzzyFilter.isEmpty()) candidates else matcher.apply(fuzzyFilter, candidates) - EmptyBehavior.MATCH_NONE -> matcher.apply(fuzzyFilter ?: "", candidates) - } - currentOrder.setAll(matches) - } - val labelList = ListView(currentOrder) + val labelList = ListView() labelList.selectionModel.selectionMode = SelectionMode.SINGLE registerStyleSheet(labelList) @@ -116,6 +108,14 @@ class MatchSelection( labelList.prefWidthProperty().bind(maxWidthProperty()) labelList.bindHeightToItemSize() + fuzzySearchField.textProperty().addListener { _, _, fuzzyFilter -> + val matches = when (emptyBehavior) { + EmptyBehavior.MATCH_ALL -> if (fuzzyFilter == null || fuzzyFilter.isEmpty()) candidates else matcher.apply(fuzzyFilter, candidates) + EmptyBehavior.MATCH_NONE -> matcher.apply(fuzzyFilter ?: "", candidates) + } + labelList.items.setAll(matches) + } + /* NOTE: I would have prefered that `labelList.scrollTo(idx)` would have worked here, * but that always calls `scrollToTop()` which we don't want. We create our own skin here,