Skip to content

Commit

Permalink
Merge pull request ddnet#7469 from archimede67/pr-save-chat-input
Browse files Browse the repository at this point in the history
Save current chat input when pressing UP. Prevent input clearing when pressing DOWN
  • Loading branch information
def- authored Nov 15, 2023
2 parents 723bda1 + 06674eb commit 55098cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/game/client/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/components/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 55098cd

Please sign in to comment.