Skip to content

Commit 2cdd9b4

Browse files
kahrlparamat
authored andcommitted
Chat: Keep scroll position constant in ChatBuffer::deleteOldest()
1 parent 0f6e4a0 commit 2cdd9b4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/chat.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void ChatBuffer::step(f32 dtime)
9797

9898
void ChatBuffer::deleteOldest(u32 count)
9999
{
100+
bool at_bottom = (m_scroll == getBottomScrollPos());
101+
100102
u32 del_unformatted = 0;
101103
u32 del_formatted = 0;
102104

@@ -120,6 +122,11 @@ void ChatBuffer::deleteOldest(u32 count)
120122

121123
m_unformatted.erase(m_unformatted.begin(), m_unformatted.begin() + del_unformatted);
122124
m_formatted.erase(m_formatted.begin(), m_formatted.begin() + del_formatted);
125+
126+
if (at_bottom)
127+
m_scroll = getBottomScrollPos();
128+
else
129+
scrollAbsolute(m_scroll - del_formatted);
123130
}
124131

125132
void ChatBuffer::deleteByAge(f32 maxAge)

0 commit comments

Comments
 (0)