Fix modified state being set when lineinput is selected.

Differentiate between text and cursor changes by adding an additional `m_WasCursorChanged`.
This commit is contained in:
Corantin H 2023-12-11 00:05:13 +01:00
parent 51220b1dfc
commit 7b20bf71e6
4 changed files with 14 additions and 6 deletions

View file

@ -1178,7 +1178,7 @@ void CChat::OnRender()
m_Input.Activate(EInputPriority::CHAT); // Ensure that the input is active
const CUIRect InputCursorRect = {Cursor.m_X, Cursor.m_Y - ScrollOffset, 0.0f, 0.0f};
const STextBoundingBox BoundingBox = m_Input.Render(&InputCursorRect, Cursor.m_FontSize, TEXTALIGN_TL, m_Input.WasChanged(), MessageMaxWidth, 0.0f);
const STextBoundingBox BoundingBox = m_Input.Render(&InputCursorRect, Cursor.m_FontSize, TEXTALIGN_TL, m_Input.WasCursorChanged(), MessageMaxWidth, 0.0f);
Graphics()->ClipDisable();

View file

@ -767,7 +767,7 @@ void CGameConsole::OnRender()
pConsole->m_Input.SetHidden(m_ConsoleType == CONSOLETYPE_REMOTE && Client()->State() == IClient::STATE_ONLINE && !Client()->RconAuthed() && (pConsole->m_UserGot || !pConsole->m_UsernameReq));
pConsole->m_Input.Activate(EInputPriority::CONSOLE); // Ensure that the input is active
const CUIRect InputCursorRect = {x, y + FONT_SIZE, 0.0f, 0.0f};
pConsole->m_BoundingBox = pConsole->m_Input.Render(&InputCursorRect, FONT_SIZE, TEXTALIGN_BL, pConsole->m_Input.WasChanged(), Screen.w - 10.0f - x, LINE_SPACING);
pConsole->m_BoundingBox = pConsole->m_Input.Render(&InputCursorRect, FONT_SIZE, TEXTALIGN_BL, pConsole->m_Input.WasCursorChanged(), Screen.w - 10.0f - x, LINE_SPACING);
if(pConsole->m_LastInputHeight == 0.0f && pConsole->m_BoundingBox.m_H != 0.0f)
pConsole->m_LastInputHeight = pConsole->m_BoundingBox.m_H;
if(pConsole->m_Input.HasSelection())

View file

@ -86,6 +86,7 @@ void CLineInput::SetRange(const char *pString, size_t Begin, size_t End)
m_Len += AddedCharSize - RemovedCharSize;
m_NumChars += AddedCharCount - RemovedCharCount;
m_WasChanged = true;
m_WasCursorChanged = true;
m_pStr[m_Len] = '\0';
m_SelectionStart = m_SelectionEnd = m_CursorPos;
}
@ -158,7 +159,7 @@ void CLineInput::MoveCursor(EMoveDirection Direction, bool MoveWord, const char
void CLineInput::SetCursorOffset(size_t Offset)
{
m_SelectionStart = m_SelectionEnd = m_LastCompositionCursorPos = m_CursorPos = clamp<size_t>(Offset, 0, m_Len);
m_WasChanged = true;
m_WasCursorChanged = true;
}
void CLineInput::SetSelection(size_t Start, size_t End)
@ -168,7 +169,7 @@ void CLineInput::SetSelection(size_t Start, size_t End)
std::swap(Start, End);
m_SelectionStart = clamp<size_t>(Start, 0, m_Len);
m_SelectionEnd = clamp<size_t>(End, 0, m_Len);
m_WasChanged = true;
m_WasCursorChanged = true;
}
size_t CLineInput::OffsetFromActualToDisplay(size_t ActualOffset)
@ -383,9 +384,9 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
}
}
m_WasChanged |= OldCursorPos != m_CursorPos;
m_WasCursorChanged |= OldCursorPos != m_CursorPos;
m_WasChanged |= SelectionLength != GetSelectionLength();
return m_WasChanged || KeyHandled;
return m_WasChanged || m_WasCursorChanged || KeyHandled;
}
STextBoundingBox CLineInput::Render(const CUIRect *pRect, float FontSize, int Align, bool Changed, float LineWidth, float LineSpacing)

View file

@ -77,6 +77,7 @@ private:
FDisplayTextCallback m_pfnDisplayTextCallback;
FCalculateOffsetCallback m_pfnCalculateOffsetCallback;
bool m_WasChanged;
bool m_WasCursorChanged;
bool m_WasRendered;
char m_ClearButtonId;
@ -179,6 +180,12 @@ public:
m_WasChanged = false;
return Changed;
}
bool WasCursorChanged()
{
const bool Changed = m_WasCursorChanged;
m_WasCursorChanged = false;
return Changed;
}
STextBoundingBox Render(const CUIRect *pRect, float FontSize, int Align, bool Changed, float LineWidth, float LineSpacing);
SMouseSelection *GetMouseSelection() { return &m_MouseSelection; }