Merge pull request #8676 from Robyt3/Client-LineInput-Event-Handling-Consistency

Consistently return `true` from `OnInput` function for used events
This commit is contained in:
heinrich5991 2024-08-07 22:07:49 +00:00 committed by GitHub
commit 83a90c9a06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View file

@ -528,26 +528,35 @@ bool CGameConsole::CInstance::OnInput(const IInput::CEvent &Event)
// Use Tab / Shift-Tab to cycle through search matches // Use Tab / Shift-Tab to cycle through search matches
SelectNextSearchMatch(Direction); SelectNextSearchMatch(Direction);
} }
Handled = true;
} }
else if(Event.m_Key == KEY_PAGEUP) else if(Event.m_Key == KEY_PAGEUP)
{ {
m_BacklogCurLine += GetLinesToScroll(-1, m_LinesRendered); m_BacklogCurLine += GetLinesToScroll(-1, m_LinesRendered);
Handled = true;
} }
else if(Event.m_Key == KEY_PAGEDOWN) else if(Event.m_Key == KEY_PAGEDOWN)
{ {
m_BacklogCurLine -= GetLinesToScroll(1, m_LinesRendered); m_BacklogCurLine -= GetLinesToScroll(1, m_LinesRendered);
if(m_BacklogCurLine < 0) if(m_BacklogCurLine < 0)
{
m_BacklogCurLine = 0; m_BacklogCurLine = 0;
}
Handled = true;
} }
else if(Event.m_Key == KEY_MOUSE_WHEEL_UP) else if(Event.m_Key == KEY_MOUSE_WHEEL_UP)
{ {
m_BacklogCurLine += GetLinesToScroll(-1, 1); m_BacklogCurLine += GetLinesToScroll(-1, 1);
Handled = true;
} }
else if(Event.m_Key == KEY_MOUSE_WHEEL_DOWN) else if(Event.m_Key == KEY_MOUSE_WHEEL_DOWN)
{ {
--m_BacklogCurLine; --m_BacklogCurLine;
if(m_BacklogCurLine < 0) if(m_BacklogCurLine < 0)
{
m_BacklogCurLine = 0; m_BacklogCurLine = 0;
}
Handled = true;
} }
// in order not to conflict with CLineInput's handling of Home/End only // in order not to conflict with CLineInput's handling of Home/End only
// react to it when the input is empty // react to it when the input is empty
@ -555,16 +564,17 @@ bool CGameConsole::CInstance::OnInput(const IInput::CEvent &Event)
{ {
m_BacklogCurLine += GetLinesToScroll(-1, -1); m_BacklogCurLine += GetLinesToScroll(-1, -1);
m_BacklogLastActiveLine = m_BacklogCurLine; m_BacklogLastActiveLine = m_BacklogCurLine;
Handled = true;
} }
else if(Event.m_Key == KEY_END && m_Input.IsEmpty()) else if(Event.m_Key == KEY_END && m_Input.IsEmpty())
{ {
m_BacklogCurLine = 0; m_BacklogCurLine = 0;
Handled = true;
} }
else if(Event.m_Key == KEY_F && m_pGameConsole->Input()->ModifierIsPressed() && Event.m_Flags & IInput::FLAG_PRESS) else if(Event.m_Key == KEY_F && m_pGameConsole->Input()->ModifierIsPressed())
{ {
m_Searching = !m_Searching; m_Searching = !m_Searching;
ClearSearch(); ClearSearch();
Handled = true; Handled = true;
} }
} }

View file

@ -199,6 +199,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
if((Event.m_Flags & IInput::FLAG_TEXT) && !(KEY_LCTRL <= Event.m_Key && Event.m_Key <= KEY_RGUI)) if((Event.m_Flags & IInput::FLAG_TEXT) && !(KEY_LCTRL <= Event.m_Key && Event.m_Key <= KEY_RGUI))
{ {
SetRange(Event.m_aText, m_SelectionStart, m_SelectionEnd); SetRange(Event.m_aText, m_SelectionStart, m_SelectionEnd);
KeyHandled = true;
} }
if(Event.m_Flags & IInput::FLAG_PRESS) if(Event.m_Flags & IInput::FLAG_PRESS)
@ -231,6 +232,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
} }
m_SelectionStart = m_SelectionEnd = m_CursorPos; m_SelectionStart = m_SelectionEnd = m_CursorPos;
} }
KeyHandled = true;
} }
else if(Event.m_Key == KEY_DELETE) else if(Event.m_Key == KEY_DELETE)
{ {
@ -251,6 +253,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
} }
m_SelectionStart = m_SelectionEnd = m_CursorPos; m_SelectionStart = m_SelectionEnd = m_CursorPos;
} }
KeyHandled = true;
} }
else if(Event.m_Key == KEY_LEFT) else if(Event.m_Key == KEY_LEFT)
{ {
@ -271,7 +274,10 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
} }
if(!Selecting) if(!Selecting)
{
m_SelectionStart = m_SelectionEnd = m_CursorPos; m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
KeyHandled = true;
} }
else if(Event.m_Key == KEY_RIGHT) else if(Event.m_Key == KEY_RIGHT)
{ {
@ -292,7 +298,10 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
} }
if(!Selecting) if(!Selecting)
{
m_SelectionStart = m_SelectionEnd = m_CursorPos; m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
KeyHandled = true;
} }
else if(Event.m_Key == KEY_HOME) else if(Event.m_Key == KEY_HOME)
{ {
@ -305,6 +314,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
m_SelectionEnd = 0; m_SelectionEnd = 0;
m_CursorPos = 0; m_CursorPos = 0;
m_SelectionStart = 0; m_SelectionStart = 0;
KeyHandled = true;
} }
else if(Event.m_Key == KEY_END) else if(Event.m_Key == KEY_END)
{ {
@ -317,6 +327,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
m_SelectionStart = m_Len; m_SelectionStart = m_Len;
m_CursorPos = m_Len; m_CursorPos = m_Len;
m_SelectionEnd = m_Len; m_SelectionEnd = m_Len;
KeyHandled = true;
} }
else if(ModPressed && !AltPressed && Event.m_Key == KEY_V) else if(ModPressed && !AltPressed && Event.m_Key == KEY_V)
{ {
@ -381,12 +392,13 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
{ {
m_SelectionStart = 0; m_SelectionStart = 0;
m_SelectionEnd = m_CursorPos = m_Len; m_SelectionEnd = m_CursorPos = m_Len;
KeyHandled = true;
} }
} }
m_WasCursorChanged |= OldCursorPos != m_CursorPos; m_WasCursorChanged |= OldCursorPos != m_CursorPos;
m_WasCursorChanged |= SelectionLength != GetSelectionLength(); m_WasCursorChanged |= SelectionLength != GetSelectionLength();
return m_WasChanged || m_WasCursorChanged || KeyHandled; return KeyHandled;
} }
STextBoundingBox CLineInput::Render(const CUIRect *pRect, float FontSize, int Align, bool Changed, float LineWidth, float LineSpacing, const std::vector<STextColorSplit> &vColorSplits) STextBoundingBox CLineInput::Render(const CUIRect *pRect, float FontSize, int Align, bool Changed, float LineWidth, float LineSpacing, const std::vector<STextColorSplit> &vColorSplits)