Skip to content

Commit

Permalink
fix: focus the inputfield when countries fragment is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph5610 committed Feb 27, 2024
1 parent 6aa8a7a commit 7cce86e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import online.hudacek.fxradio.ui.menu.platformContextMenu
import online.hudacek.fxradio.ui.style.Styles
import online.hudacek.fxradio.ui.util.flagIcon
import online.hudacek.fxradio.ui.util.make
import online.hudacek.fxradio.ui.util.requestFocusOnSceneAvailable
import online.hudacek.fxradio.ui.util.searchField
import online.hudacek.fxradio.ui.util.showWhen
import online.hudacek.fxradio.viewmodel.LibraryState
Expand Down Expand Up @@ -67,6 +68,9 @@ class CountriesSearchFragment : BaseFragment() {
alignment = Pos.CENTER
padding = insets(5, 9)
}
requestFocusOnSceneAvailable {
selectAll()
}
}

label(messages["directory.error"]) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/online/hudacek/fxradio/ui/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ private const val NOTIFICATION_TIME_ON_SCREEN = 3.0
* This is to overcome a bug that sometimes
* scene is not available when requesting focus
*/
internal fun Node.requestFocusOnSceneAvailable() = if (scene == null) {
internal fun Node.requestFocusOnSceneAvailable(action: () -> Unit = {}) = if (scene == null) {
val listener = object : ChangeListener<Scene> {
override fun changed(observable: ObservableValue<out Scene>?, oldValue: Scene?, newValue: Scene?) {
if (newValue != null) {
sceneProperty().removeListener(this)
requestFocus()
action()
}
}
}
Expand Down

0 comments on commit 7cce86e

Please sign in to comment.