Chat: Keep scroll position constant in ChatBuffer::deleteOldest()
authorKahrl <kahrl@gmx.net>
Tue, 23 Apr 2013 21:17:33 +0000 (23:17 +0200)
committerparamat <mat.gregory@virginmedia.com>
Sun, 8 May 2016 01:51:23 +0000 (02:51 +0100)
src/chat.cpp

index ab945444f5f043f73225a00723e9521d1b9b0814..cebe312257cc335c1fc21f2ec21992a0a01e1d9d 100644 (file)
@@ -97,6 +97,8 @@ void ChatBuffer::step(f32 dtime)
 
 void ChatBuffer::deleteOldest(u32 count)
 {
+       bool at_bottom = (m_scroll == getBottomScrollPos());
+
        u32 del_unformatted = 0;
        u32 del_formatted = 0;
 
@@ -120,6 +122,11 @@ void ChatBuffer::deleteOldest(u32 count)
 
        m_unformatted.erase(m_unformatted.begin(), m_unformatted.begin() + del_unformatted);
        m_formatted.erase(m_formatted.begin(), m_formatted.begin() + del_formatted);
+
+       if (at_bottom)
+               m_scroll = getBottomScrollPos();
+       else
+               scrollAbsolute(m_scroll - del_formatted);
 }
 
 void ChatBuffer::deleteByAge(f32 maxAge)