diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 324e316b..8b8b9fea 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -234,18 +234,18 @@ void CConsole::DrawSurface(void) if (m_nSuggestPos != -1) { // Remove the default value from ConVar before assigning it to the input buffer. - string svConVar = m_vSuggest[m_nSuggestPos].m_svName.substr(0, m_vSuggest[m_nSuggestPos].m_svName.find(' ')) + ' '; - memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1); + m_svInputConVar = m_vSuggest[m_nSuggestPos].m_svName.substr(0, m_vSuggest[m_nSuggestPos].m_svName.find(' ')) + ' '; + m_bModifyInput = true; ResetAutoComplete(); - BuildSummary(svConVar); + BuildSummary(m_svInputConVar); } else { if (m_szInputBuf[0]) { ProcessCommand(m_szInputBuf); - memset(m_szInputBuf, '\0', 1); + m_bModifyInput = true; } ResetAutoComplete(); @@ -809,6 +809,21 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData) BuildSummary(iData->Buf); break; } + case ImGuiInputTextFlags_CallbackAlways: + { + if (m_bModifyInput) + { + iData->DeleteChars(0, iData->BufTextLen); + if (!m_svInputConVar.empty()) + { + iData->InsertChars(0, m_svInputConVar.c_str()); + m_svInputConVar.clear(); + } + m_bModifyInput = false; + } + + break; + } case ImGuiInputTextFlags_CallbackEdit: { for (size_t i = 0, n = strlen(iData->Buf); i < n; i++) diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index 7fbfaceb..17089235 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -65,6 +65,7 @@ private: vector m_vCommands; vector m_vHistory; + string m_svInputConVar; ssize_t m_nHistoryPos = -1; int m_nScrollBack = 0; int m_nSelectBack = 0; @@ -75,6 +76,7 @@ private: bool m_bInitialized = false; bool m_bReclaimFocus = false; bool m_bCopyToClipBoard = false; + bool m_bModifyInput = false; bool m_bCanAutoComplete = false; bool m_bSuggestActive = false; @@ -97,7 +99,7 @@ private: ImGuiInputTextFlags_CallbackAlways | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue | - ImGuiInputTextFlags_NoUndoRedo; + ImGuiInputTextFlags_NoUndoRedo; // This flag will be removed when the ImGui lib is updated to v1.88 (see https://github.com/ocornut/imgui/issues/4947). ImGuiWindowFlags m_nSuggestFlags = ImGuiWindowFlags_NoMove |