From 907ddf8b24ea65700d9befb2dcd13322dfc8aeec Mon Sep 17 00:00:00 2001 From: pierow Date: Mon, 4 Jan 2021 13:40:19 -0500 Subject: [PATCH] Fix for backspace being held preventing additional text input. Credit to Bacsu. --- .../cl_dll/vgui_TeamFortressViewport.cpp | 2 +- main/source/ui/ChatPanel.cpp | 20 ++++++++++++------- main/source/ui/ChatPanel.h | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/main/source/cl_dll/vgui_TeamFortressViewport.cpp b/main/source/cl_dll/vgui_TeamFortressViewport.cpp index 4fb5e6d7..2e673416 100644 --- a/main/source/cl_dll/vgui_TeamFortressViewport.cpp +++ b/main/source/cl_dll/vgui_TeamFortressViewport.cpp @@ -2388,7 +2388,7 @@ int TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrent if (m_chatPanel->isVisible()) { // Don't let the game handle the input while the user is typing in the chat window. - m_chatPanel->KeyEvent(); + m_chatPanel->KeyEvent(down); return 0; } diff --git a/main/source/ui/ChatPanel.cpp b/main/source/ui/ChatPanel.cpp index 69c98513..208f153d 100644 --- a/main/source/ui/ChatPanel.cpp +++ b/main/source/ui/ChatPanel.cpp @@ -208,10 +208,11 @@ std::string ChatPanel::UTF8toASCII(unsigned char* multibyte) return ASCIIValue; } -void ChatPanel::KeyEvent() +void ChatPanel::KeyEvent(int iKeydown) { - const Uint8 *state = SDL_GetKeyboardState(NULL); - + const Uint8 *state = SDL_GetKeyboardState(NULL); + bool bTextinput; + bTextinput = false; while (SDL_PollEvent(&event)) { if (event.type == SDL_TEXTINPUT) @@ -220,20 +221,25 @@ void ChatPanel::KeyEvent() buffer = (unsigned char*)event.text.text; mText += UTF8toASCII(buffer); + bTextinput = true; } } if (state[SDL_SCANCODE_ESCAPE]) { - CancelChat(); + CancelChat(); + } if (state[SDL_SCANCODE_BACKSPACE]) { - if (mText.length() > 0) + if (iKeydown && !bTextinput) { - mText.erase(mText.length() - 1, mText.length()); - } + if (mText.length() > 0) + { + mText.erase(mText.length() - 1, mText.length()); + } + } } if (state[SDL_SCANCODE_RETURN]) { diff --git a/main/source/ui/ChatPanel.h b/main/source/ui/ChatPanel.h index 54caa9b8..23e4d014 100644 --- a/main/source/ui/ChatPanel.h +++ b/main/source/ui/ChatPanel.h @@ -20,7 +20,7 @@ public: void CancelChat(); void SetChatMode(std::string sChatMode); - void KeyEvent(); + void KeyEvent(int iKeydown); void KeyDown(int virtualKey, int scanCode); // Checks if a key was pushed since the chat window was opened.