From 5dd5f2ad11f90707815b21ec411f9cf4d4741cab Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 10 Nov 2022 22:01:34 +0100 Subject: [PATCH] Fix issue caused by iData->BufTextLen always being NULL in ImGuiInputTextFlags_CallbackCharFilter iData->BufTextLen is always 0 in the ImGuiInputTextFlags_CallbackCharFilter event. ImGuiInputTextFlags_CallbackAlways is called before ImGuiInputTextFlags_CallbackCharFilter in the same frame, so we can obtain the lenght from there and perform the test to discard unwanted characters from the input field. --- r5dev/gameui/IConsole.cpp | 8 +++++--- r5dev/gameui/IConsole.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index d69f52bf..ffeac60a 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -34,6 +34,7 @@ CConsole::CConsole(void) , m_nSuggestPos(-1) , m_nScrollBack(0) , m_nSelectBack(0) + , m_nInputTextLen(0) , m_flScrollX(0.f) , m_flScrollY(0.f) , m_flFadeAlpha(0.f) @@ -851,9 +852,10 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData) } case ImGuiInputTextFlags_CallbackAlways: { + m_nInputTextLen = iData->BufTextLen; if (m_bModifyInput) // User entered a value in the input field. { - iData->DeleteChars(0, iData->BufTextLen); + iData->DeleteChars(0, m_nInputTextLen); m_bSuggestActive = false; if (!m_svInputConVar.empty()) // User selected a ConVar from the suggestion window, copy it to the buffer. @@ -868,7 +870,7 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData) case ImGuiInputTextFlags_CallbackCharFilter: { const ImWchar c = iData->EventChar; - if (!iData->BufTextLen) + if (!m_nInputTextLen) { if (c == '~' || c == ' ') // Discard space and tilde character as first input. { @@ -886,7 +888,7 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData) } case ImGuiInputTextFlags_CallbackEdit: { - if (iData->BufTextLen) + if (iData->BufTextLen) // Attempt to build a summary.. { m_bCanAutoComplete = true; BuildSummary(iData->Buf); diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index f6eb1012..a187df63 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -72,6 +72,7 @@ private: ssize_t m_nSuggestPos; int m_nScrollBack; int m_nSelectBack; + int m_nInputTextLen; float m_flScrollX; float m_flScrollY; float m_flFadeAlpha;