diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 05f85be3b..18600da21 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -92,6 +92,7 @@ void CChat::Reset() m_Show = false; m_InputUpdate = false; m_ChatStringOffset = 0; + m_CompletionUsed = false; m_CompletionChosen = -1; m_aCompletionBuffer[0] = 0; m_PlaceholderOffset = 0; @@ -309,7 +310,7 @@ bool CChat::OnInput(IInput::CEvent Event) if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_TAB) { // fill the completion buffer - if(m_CompletionChosen < 0) + if(!m_CompletionUsed) { const char *pCursor = m_Input.GetString() + m_Input.GetCursorOffset(); for(int Count = 0; Count < m_Input.GetCursorOffset() && *(pCursor - 1) != ' '; --pCursor, ++Count) @@ -328,10 +329,13 @@ bool CChat::OnInput(IInput::CEvent Event) const size_t NumCommands = m_Commands.size(); - if(m_ReverseTAB) - m_CompletionChosen = (m_CompletionChosen - 1 + 2 * NumCommands) % (2 * NumCommands); - else - m_CompletionChosen = (m_CompletionChosen + 1) % (2 * NumCommands); + if(m_ReverseTAB && m_CompletionUsed) + m_CompletionChosen--; + else if(!m_ReverseTAB) + m_CompletionChosen++; + m_CompletionChosen = (m_CompletionChosen + 2 * NumCommands) % (2 * NumCommands); + + m_CompletionUsed = true; const char *pCommandStart = m_aCompletionBuffer + 1; for(size_t i = 0; i < 2 * NumCommands; ++i) @@ -392,10 +396,13 @@ bool CChat::OnInput(IInput::CEvent Event) // find next possible name const char *pCompletionString = 0; - if(m_ReverseTAB) - m_CompletionChosen = (m_CompletionChosen - 1 + 2 * MAX_CLIENTS) % (2 * MAX_CLIENTS); - else - m_CompletionChosen = (m_CompletionChosen + 1) % (2 * MAX_CLIENTS); + if(m_ReverseTAB && m_CompletionUsed) + m_CompletionChosen--; + else if(!m_ReverseTAB) + m_CompletionChosen++; + m_CompletionChosen = (m_CompletionChosen + 2 * MAX_CLIENTS) % (2 * MAX_CLIENTS); + + m_CompletionUsed = true; for(int i = 0; i < 2 * MAX_CLIENTS; ++i) { @@ -470,8 +477,13 @@ bool CChat::OnInput(IInput::CEvent Event) { // reset name completion process if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key != KEY_TAB) + { if(Event.m_Key != KEY_LSHIFT) + { m_CompletionChosen = -1; + m_CompletionUsed = false; + } + } m_OldChatStringLength = m_Input.GetLength(); m_Input.ProcessInput(Event); @@ -529,6 +541,7 @@ void CChat::EnableMode(int Team) Input()->SetIMEState(true); Input()->Clear(); m_CompletionChosen = -1; + m_CompletionUsed = false; } } diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h index 97eb5946f..4785f96ff 100644 --- a/src/game/client/components/chat.h +++ b/src/game/client/components/chat.h @@ -75,6 +75,7 @@ class CChat : public CComponent bool m_InputUpdate; int m_ChatStringOffset; int m_OldChatStringLength; + bool m_CompletionUsed; int m_CompletionChosen; char m_aCompletionBuffer[256]; int m_PlaceholderOffset; diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index f01df4229..eb8d50fa2 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -47,6 +47,7 @@ CGameConsole::CInstance::CInstance(int Type) m_CompletionFlagmask = CFGFLAG_SERVER; m_aCompletionBuffer[0] = 0; + m_CompletionUsed = false; m_CompletionChosen = -1; m_CompletionRenderOffset = 0.0f; m_ReverseTAB = false; @@ -255,13 +256,15 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) { if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed()) { - if(m_ReverseTAB) + if(m_ReverseTAB && m_CompletionUsed) m_CompletionChosen--; - else + else if(!m_ReverseTAB) m_CompletionChosen++; m_CompletionEnumerationCount = 0; m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this); + m_CompletionUsed = true; + // handle wrapping if(m_CompletionEnumerationCount && (m_CompletionChosen >= m_CompletionEnumerationCount || m_CompletionChosen < 0)) { @@ -310,6 +313,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) { if((Event.m_Key != KEY_TAB) && (Event.m_Key != KEY_LSHIFT)) { + m_CompletionUsed = false; m_CompletionChosen = -1; str_copy(m_aCompletionBuffer, m_Input.GetString(), sizeof(m_aCompletionBuffer)); m_CompletionRenderOffset = 0.0f; @@ -540,7 +544,7 @@ void CGameConsole::OnRender() CRenderInfo Info; Info.m_pSelf = this; - Info.m_WantedCompletion = pConsole->m_CompletionChosen; + Info.m_WantedCompletion = pConsole->m_CompletionUsed ? pConsole->m_CompletionChosen : -1; Info.m_EnumCount = 0; Info.m_Offset = pConsole->m_CompletionRenderOffset; Info.m_Width = Screen.w; diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index 846232d21..7f332b4d1 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -40,6 +40,7 @@ class CGameConsole : public CComponent CGameConsole *m_pGameConsole; char m_aCompletionBuffer[128]; + bool m_CompletionUsed; int m_CompletionChosen; int m_CompletionFlagmask; float m_CompletionRenderOffset;