From 4428baae41f184deaf48fc7cdcd42b8660c5eb69 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 2 Dec 2022 15:51:26 -0500 Subject: [PATCH] Bug fixes --- CHANGELOG.md | 2 ++ src/components/SearchScreen/SearchScreen.bs | 22 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f681e52f..d54b28ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bug where logging in causes issues if a video is already playing - Bug where casting from web app while playing a video from the search - Spinner for the video +- Bug where search sugggestions selected index is higher than total count +- Race condition where button group gains focus before suggestions are set in Search Page ## [0.4.0] - 2022-11-24 ### Added diff --git a/src/components/SearchScreen/SearchScreen.bs b/src/components/SearchScreen/SearchScreen.bs index c82f01bc..e82ec4d1 100644 --- a/src/components/SearchScreen/SearchScreen.bs +++ b/src/components/SearchScreen/SearchScreen.bs @@ -29,6 +29,9 @@ function OnFocusChange() as void return end if if m.suggestions.buttons.Count() > 0 + if m.suggestions.buttonFocused >= m.suggestions.buttons.Count() + m.suggestions.focusButton = 0 + end if m.suggestions.SetFocus(true) return end if @@ -57,8 +60,19 @@ function OnTextChange() as void if q.len() > 0 and ArrayIndexOf(suggestions, q) = -1 suggestions.Unshift(q) end if - ' TODO: fix race condition where button group gains focus before suggestions are set + + ' Capture current focused button and restore it after resetting the buttons + buttonFocused = -1 + if IsNodeFocused("suggestions") + buttonFocused = m.suggestions.buttonFocused + end if + if buttonFocused >= m.suggestions.buttons.Count() + buttonFocused = m.suggestions.buttons.Count() -1 + end if m.suggestions.buttons = suggestions + if buttonFocused <> -1 + m.suggestions.focusButton = buttonFocused + end if end if end function) end function @@ -69,7 +83,11 @@ function OnSearchButtonSelected() Search(text) end function -function OnSearchButtonFocused() +function OnSearchButtonFocused() as void + if not IsNodeFocused("suggestions") + return + end if + selected = m.suggestions.buttonFocused text = m.suggestions.buttons[selected] m.keyboard.text = text