fix(input): editor Reset keeps the D-pad direction overrides

This commit is contained in:
Kurt Himebauch committed 2026-11-18 21:04:52 -05:00
1 parent bf75dfb9c0
commit 732c97831d
2 files changed
+13 -1

No files matched your search

@@ -112,7 +112,7 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
fun reset() {
val d = restored?.takeIf { !atDefaults } ?: return
checkpoint(); elements = d; selected = null
actions = actions.filterKeys { id -> d.any { it.id == id } }; clicks = clicks.filterKeys { id -> d.any { it.id == id } }
actions = actions.filterKeys { id -> KitLayout.bindsTo(id, d) }; clicks = clicks.filterKeys { id -> d.any { it.id == id } }
}
fun hiddenDefaults(): List<InputSurfaceElement> = defaults?.let { refit(it, defaultsFrame) }?.filter { d -> elements.none { it.id == d.id } }.orEmpty()
fun add(element: InputSurfaceElement) { checkpoint(); elements = elements + element; selected = element.id; popover = null }
@@ -219,6 +219,18 @@ class InputSettingsTest {
compose.runOnIdle { assertTrue(OnScreenLayout.generated(InputLibraries.read(context).layouts.first { it.id == layout.id })) }
}
@Test fun resetAndSaveKeepTheDpadDirectionOverrides() {
val library = InputLibraries.read(context)
val layout = library.layout("game", InputRole.PRIMARY)!!
val bindingsId = library.profile("game").binding(InputRole.PRIMARY)
InputLibraries.update(context) { lib -> lib.preset(bindingsId).let { b -> lib.withPreset(b.copy(elements = b.elements + ("legacy:up" to InputAction.Keys(listOf(103))))) } }
compose.setContent { DroidDeckTheme { InputSurfaceDialog("game", {}, {}, role = InputRole.PRIMARY, layoutId = layout.id, bindingsId = bindingsId) } }
pressPlus(2)
compose.onNodeWithText(context.getString(R.string.hud_reset_button)).performScrollTo().performClick()
compose.onNodeWithText(context.getString(R.string.input_editor_done)).performScrollTo().performClick()
compose.runOnIdle { assertEquals(InputAction.Keys(listOf(103)), InputLibraries.read(context).preset(bindingsId).elements["legacy:up"]) }
}
@Test fun deckPresetOffersItsRealElementsAndTheCommonEditor() {
InputLibraries.update(context) { it.useLayout("game", InputRole.SECONDARY, InputLibraries.DECK, shared = true) }
compose.setContent { DroidDeckTheme { InputSettingsPage({}) } }