diff --git a/src/components/SearchScreen/SearchScreen.bs b/src/components/SearchScreen/SearchScreen.bs index c328ad78..ba808109 100644 --- a/src/components/SearchScreen/SearchScreen.bs +++ b/src/components/SearchScreen/SearchScreen.bs @@ -12,6 +12,7 @@ function Init() m.keyboard.ObserveField("text", "OnTextChange") m.suggestions.ObserveField("buttonSelected", "OnSearchButtonSelected") + m.suggestions.ObserveField("buttonFocused", "OnSearchButtonFocused") m.rowList.ObserveField("rowItemSelected", "OnSearchVideoSelected") m.top.ObserveField("focus", "OnFocusChange") m.top.ObserveField("visible", "OnVisibilityChange") @@ -36,6 +37,9 @@ function OnFocusChange() as void end function function OnTextChange() as void + if IsNodeFocused("suggestions") + return + end if text = m.keyboard.text createTaskPromise("SearchSuggestionsTask", { @@ -47,8 +51,12 @@ function OnTextChange() as void if task.output.q <> m.keyboard.text return end if + q = task.output.q suggestions = task.output.response if suggestions <> invalid + 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 m.suggestions.buttons = suggestions end if @@ -61,6 +69,12 @@ function OnSearchButtonSelected() Search(text) end function +function OnSearchButtonFocused() + selected = m.suggestions.buttonFocused + text = m.suggestions.buttons[selected] + m.keyboard.text = text +end function + function Search(text as string) SaveSearchHistory(text) createTaskPromise("SearchTask", { @@ -93,7 +107,7 @@ function ClearSearch() end function function IsNodeFocused(id as string) as boolean - return m.top.focusedChild.id = id or m.container.focusedChild.id = id + return m.top.focusedChild?.id = id or m.container.focusedChild?.id = id end function function ScrollUp() as void