Merge pull request #7469 from archimede67/pr-save-chat-input

Save current chat input when pressing UP. Prevent input clearing when pressing DOWN
This commit is contained in:
Dennis Felsing 2023-11-15 23:20:13 +00:00 committed by GitHub
commit 55098cd313
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -120,6 +120,8 @@ void CChat::Reset()
m_LastChatSend = 0;
m_CurrentLine = 0;
m_IsInputCensored = false;
m_EditingNewLine = true;
mem_zero(m_aCurrentInputText, sizeof(m_aCurrentInputText));
DisableMode();
for(int64_t &LastSoundPlayed : m_aLastSoundPlayed)
@ -426,6 +428,12 @@ bool CChat::OnInput(const IInput::CEvent &Event)
if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_UP)
{
if(m_EditingNewLine)
{
str_copy(m_aCurrentInputText, m_Input.GetString());
m_EditingNewLine = false;
}
if(m_pHistoryEntry)
{
CHistoryEntry *pTest = m_History.Prev(m_pHistoryEntry);
@ -445,9 +453,14 @@ bool CChat::OnInput(const IInput::CEvent &Event)
m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
if(m_pHistoryEntry)
{
m_Input.Set(m_pHistoryEntry->m_aText);
else
m_Input.Clear();
}
else if(!m_EditingNewLine)
{
m_Input.Set(m_aCurrentInputText);
m_EditingNewLine = true;
}
}
return true;

View file

@ -123,6 +123,8 @@ class CChat : public CComponent
int64_t m_LastChatSend;
int64_t m_aLastSoundPlayed[CHAT_NUM];
bool m_IsInputCensored;
char m_aCurrentInputText[MAX_LINE_LENGTH];
bool m_EditingNewLine;
static void ConSay(IConsole::IResult *pResult, void *pUserData);
static void ConSayTeam(IConsole::IResult *pResult, void *pUserData);