From 97fffaf49ef73d9a84afdbaa37736ca043d9ac00 Mon Sep 17 00:00:00 2001 From: Stepan Hembarovskyi Date: Sat, 10 Jan 2026 20:06:47 +0200 Subject: [PATCH] fix: Correctly handles unbound keybinds (#2854) Resolves #2652 #2291 ## Description: Resolves a regression after a new design changes where keybinds explicitly set to "Null" were incorrectly reverted to default values instead of remaining unbound. Updates the input handler to preserve "Null" as the designated value for an unbound key. The UI now reflects this by displaying "None" for keybinds that are set to "Null", providing clear user feedback. Before/After: image image ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: webdev.js Co-authored-by: antigrid --- src/client/InputHandler.ts | 2 +- .../components/baseComponents/setting/SettingKeybind.ts | 2 +- tests/InputHandler.test.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/client/InputHandler.ts b/src/client/InputHandler.ts index 3bd9378b0..949da78d5 100644 --- a/src/client/InputHandler.ts +++ b/src/client/InputHandler.ts @@ -185,7 +185,7 @@ export class InputHandler { } // Map invalid values to undefined (filtered later) - if (typeof val !== "string" || val === "Null") { + if (typeof val !== "string") { return [k, undefined]; } return [k, val]; diff --git a/src/client/components/baseComponents/setting/SettingKeybind.ts b/src/client/components/baseComponents/setting/SettingKeybind.ts index 50b7a8284..ed3582ad0 100644 --- a/src/client/components/baseComponents/setting/SettingKeybind.ts +++ b/src/client/components/baseComponents/setting/SettingKeybind.ts @@ -78,7 +78,7 @@ export class SettingKeybind extends LitElement { } private displayKey(key: string): string { - if (!key) return translateText("user_setting.press_a_key"); + if (!key || key === "Null") return translateText("common.none"); return formatKeyForDisplay(key); } diff --git a/tests/InputHandler.test.ts b/tests/InputHandler.test.ts index e854cb11a..132e88419 100644 --- a/tests/InputHandler.test.ts +++ b/tests/InputHandler.test.ts @@ -426,7 +426,7 @@ describe("InputHandler AutoUpgrade", () => { expect((inputHandler as any).keybinds.moveUp).toBe("KeyX"); }); - test("ignores non-string and 'Null' values and preserves defaults", () => { + test("ignores non-string values and preserves defaults, but keeps 'Null' for unbound keys", () => { const mixed = { moveUp: { key: "moveUp", value: null }, moveLeft: "Null", @@ -435,9 +435,9 @@ describe("InputHandler AutoUpgrade", () => { inputHandler.initialize(); - // defaults from InputHandler should remain expect((inputHandler as any).keybinds.moveUp).toBe("KeyW"); - expect((inputHandler as any).keybinds.moveLeft).toBe("KeyA"); + // "Null" is preserved to indicate unbound keybind + expect((inputHandler as any).keybinds.moveLeft).toBe("Null"); }); test("handles invalid JSON gracefully and warns", () => {