From a5b877de676eb840f07abe636247acb61430b4e2 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 14 Mar 2026 03:54:26 -0700 Subject: [PATCH] fix(chat): suppress alnum hotkeys while typing --- src/ui/game_screen.cpp | 29 +++++++++++++++-------------- src/ui/keybinding_manager.cpp | 14 +++++++++++++- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index cfbbf1ae..a9efe484 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -2274,7 +2274,21 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { void GameScreen::processTargetInput(game::GameHandler& gameHandler) { auto& io = ImGui::GetIO(); auto& input = core::Input::getInstance(); - const bool textFocus = chatInputActive || io.WantTextInput; + + // If the user is typing (or about to focus chat this frame), do not allow + // A-Z or 1-0 shortcuts to fire. + if (!io.WantTextInput && !chatInputActive && input.isKeyJustPressed(SDL_SCANCODE_SLASH)) { + refocusChatInput = true; + chatInputBuffer[0] = '/'; + chatInputBuffer[1] = '\0'; + chatInputMoveCursorToEnd = true; + } + if (!io.WantTextInput && !chatInputActive && + KeybindingManager::getInstance().isActionPressed(KeybindingManager::Action::TOGGLE_CHAT, true)) { + refocusChatInput = true; + } + + const bool textFocus = chatInputActive || refocusChatInput || io.WantTextInput; // Tab targeting (when keyboard not captured by UI) if (!io.WantCaptureKeyboard) { @@ -2372,19 +2386,6 @@ void GameScreen::processTargetInput(game::GameHandler& gameHandler) { } - // Slash key: focus chat input — always works unless already typing in chat - if (!chatInputActive && input.isKeyJustPressed(SDL_SCANCODE_SLASH)) { - refocusChatInput = true; - chatInputBuffer[0] = '/'; - chatInputBuffer[1] = '\0'; - chatInputMoveCursorToEnd = true; - } - - // Enter key: focus chat input (empty) — always works unless already typing - if (!chatInputActive && KeybindingManager::getInstance().isActionPressed(KeybindingManager::Action::TOGGLE_CHAT, true)) { - refocusChatInput = true; - } - // Cursor affordance: show hand cursor over interactable game objects. if (!io.WantCaptureMouse) { auto* renderer = core::Application::getInstance().getRenderer(); diff --git a/src/ui/keybinding_manager.cpp b/src/ui/keybinding_manager.cpp index 4b3b4535..a96a040e 100644 --- a/src/ui/keybinding_manager.cpp +++ b/src/ui/keybinding_manager.cpp @@ -42,7 +42,19 @@ void KeybindingManager::initializeDefaults() { bool KeybindingManager::isActionPressed(Action action, bool repeat) { auto it = bindings_.find(static_cast(action)); if (it == bindings_.end()) return false; - return ImGui::IsKeyPressed(it->second, repeat); + ImGuiKey key = it->second; + if (key == ImGuiKey_None) return false; + + // When typing in a text field (e.g. chat input), never treat A-Z or 0-9 as shortcuts. + const ImGuiIO& io = ImGui::GetIO(); + if (io.WantTextInput) { + if ((key >= ImGuiKey_A && key <= ImGuiKey_Z) || + (key >= ImGuiKey_0 && key <= ImGuiKey_9)) { + return false; + } + } + + return ImGui::IsKeyPressed(key, repeat); } ImGuiKey KeybindingManager::getKeyForAction(Action action) const {