Fix for backspace being held preventing additional text input. Credit to Bacsu.

This commit is contained in:
pierow 2021-01-04 13:40:19 -05:00
parent 6d75594419
commit 907ddf8b24
3 changed files with 15 additions and 9 deletions

View file

@ -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;
}

View file

@ -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);
bool bTextinput;
bTextinput = false;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_TEXTINPUT)
@ -220,6 +221,7 @@ void ChatPanel::KeyEvent()
buffer = (unsigned char*)event.text.text;
mText += UTF8toASCII(buffer);
bTextinput = true;
}
}
@ -227,14 +229,18 @@ void ChatPanel::KeyEvent()
if (state[SDL_SCANCODE_ESCAPE])
{
CancelChat();
}
if (state[SDL_SCANCODE_BACKSPACE])
{
if (iKeydown && !bTextinput)
{
if (mText.length() > 0)
{
mText.erase(mText.length() - 1, mText.length());
}
}
}
if (state[SDL_SCANCODE_RETURN])
{
std::string theCommand;

View file

@ -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.