Skip to content

Commit

Permalink
Consistently return true from OnInput function for used events
Browse files Browse the repository at this point in the history
The `OnInput` function should return `true` exactly for events that were handled. In case of line inputs, the function returned `true` when then line input was changed instead. For the consoles, the function did not return `true` for some events that were handled.
  • Loading branch information
Robyt3 committed Aug 3, 2024
1 parent 00d941a commit bdd7784
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/game/client/components/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,43 +528,53 @@ bool CGameConsole::CInstance::OnInput(const IInput::CEvent &Event)
// Use Tab / Shift-Tab to cycle through search matches
SelectNextSearchMatch(Direction);
}
Handled = true;
}
else if(Event.m_Key == KEY_PAGEUP)
{
m_BacklogCurLine += GetLinesToScroll(-1, m_LinesRendered);
Handled = true;
}
else if(Event.m_Key == KEY_PAGEDOWN)
{
m_BacklogCurLine -= GetLinesToScroll(1, m_LinesRendered);
if(m_BacklogCurLine < 0)
{
m_BacklogCurLine = 0;
}
Handled = true;
}
else if(Event.m_Key == KEY_MOUSE_WHEEL_UP)
{
m_BacklogCurLine += GetLinesToScroll(-1, 1);
Handled = true;
}
else if(Event.m_Key == KEY_MOUSE_WHEEL_DOWN)
{
--m_BacklogCurLine;
if(m_BacklogCurLine < 0)
{
m_BacklogCurLine = 0;
}
Handled = true;
}
// in order not to conflict with CLineInput's handling of Home/End only
// react to it when the input is empty
else if(Event.m_Key == KEY_HOME && m_Input.IsEmpty())
{
m_BacklogCurLine += GetLinesToScroll(-1, -1);
m_BacklogLastActiveLine = m_BacklogCurLine;
Handled = true;
}
else if(Event.m_Key == KEY_END && m_Input.IsEmpty())
{
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;
ClearSearch();

Handled = true;
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/game/client/lineinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
SetRange(Event.m_aText, m_SelectionStart, m_SelectionEnd);
KeyHandled = true;
}

if(Event.m_Flags & IInput::FLAG_PRESS)
Expand Down Expand Up @@ -231,6 +232,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
}
m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
KeyHandled = true;
}
else if(Event.m_Key == KEY_DELETE)
{
Expand All @@ -251,6 +253,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
}
m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
KeyHandled = true;
}
else if(Event.m_Key == KEY_LEFT)
{
Expand All @@ -271,7 +274,10 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
}

if(!Selecting)
{
m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
KeyHandled = true;
}
else if(Event.m_Key == KEY_RIGHT)
{
Expand All @@ -292,7 +298,10 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
}

if(!Selecting)
{
m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
KeyHandled = true;
}
else if(Event.m_Key == KEY_HOME)
{
Expand All @@ -305,6 +314,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
m_SelectionEnd = 0;
m_CursorPos = 0;
m_SelectionStart = 0;
KeyHandled = true;
}
else if(Event.m_Key == KEY_END)
{
Expand All @@ -317,6 +327,7 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
m_SelectionStart = m_Len;
m_CursorPos = m_Len;
m_SelectionEnd = m_Len;
KeyHandled = true;
}
else if(ModPressed && !AltPressed && Event.m_Key == KEY_V)
{
Expand Down Expand Up @@ -381,12 +392,13 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
{
m_SelectionStart = 0;
m_SelectionEnd = m_CursorPos = m_Len;
KeyHandled = true;
}
}

m_WasCursorChanged |= OldCursorPos != m_CursorPos;
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)
Expand Down

0 comments on commit bdd7784

Please sign in to comment.