From e49aa9b7d807c2f6058a642e2ec6d01641e451e7 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 6 Jul 2023 16:08:54 -0400 Subject: [PATCH] Fix for input field focus --- CHANGELOG.md | 1 + .../SettingsScreen/SettingsScreen.bs | 19 +++++++++++++------ .../SettingsScreen/StringControl.bs | 7 ------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daad8b04..4de6ecba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Crash when loading the home screen [#83](https://github.com/iBicha/playlet/issues/83) - Performance of home screen in web app - SponsorBlock segments where video duration is not provided (follow up to [#23](https://github.com/iBicha/playlet/pull/23)) +- Focus with the settings input field ## [0.10.1] - 2023-06-28 diff --git a/playlet-lib/src/components/SettingsScreen/SettingsScreen.bs b/playlet-lib/src/components/SettingsScreen/SettingsScreen.bs index f3f28938..e08e3898 100644 --- a/playlet-lib/src/components/SettingsScreen/SettingsScreen.bs +++ b/playlet-lib/src/components/SettingsScreen/SettingsScreen.bs @@ -275,18 +275,22 @@ function OnkeyEvent(key as string, press as boolean) as boolean end function function GetFocusedControl() as object - focusedChild = m.top.focusedChild - if focusedChild = invalid + node = m.top.focusedChild + if node = invalid return invalid end if - while not focusedChild.id.StartsWith("Control") - focusedChild = focusedChild.focusedChild - if focusedChild = invalid + while not node.id.StartsWith("Control") + child = node.focusedChild + if child = invalid return invalid end if + if node.isSameNode(child) + return invalid + end if + node = child end while - return focusedChild + return node end function function MenuGoLeft() as boolean @@ -299,6 +303,9 @@ end function function MenuNavigate(direction as integer) as boolean focusedControl = GetFocusedControl() + if focusedControl = invalid + return false + end if container = focusedControl.getParent() containerParent = container.getParent() containerCount = containerParent.getChildCount() diff --git a/playlet-lib/src/components/SettingsScreen/StringControl.bs b/playlet-lib/src/components/SettingsScreen/StringControl.bs index 686923f9..ed708b47 100644 --- a/playlet-lib/src/components/SettingsScreen/StringControl.bs +++ b/playlet-lib/src/components/SettingsScreen/StringControl.bs @@ -3,7 +3,6 @@ function Init() m.top.observeField("focusedChild", "OnFocusChanged") m.top.observeField("value", "OnValueChanged") m.top.observeField("settings", "OnSettingsScreen") - m.keyboardWasClosedByButton = false end function function OnSettingsScreen() @@ -45,15 +44,9 @@ function OnButtonSelected(event as object) if buttonSelected = 0 m.top.value = keyboard.text end if - m.keyboardWasClosedByButton = true keyboard.close = true end function function OnKeyboardClosed() as void - ' The keyboard was closed by something else (like cast from web app) - ' In this case, we do nothing, since the focus might be moved to the video player - if not m.keyboardWasClosedByButton - return - end if m.top.settings@.MenuNavigate(-1) end function