From ad523f37c5f322f6ba93e454e31246ae3acdad33 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 6 Oct 2021 02:30:30 -0400 Subject: preserve scroll position when loading history it still jumps around a bit sometimes but its acceptable. hopefully there is a better solution --- components/chatlist.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'components/chatlist.hpp') diff --git a/components/chatlist.hpp b/components/chatlist.hpp index 2122e49..e5afb80 100644 --- a/components/chatlist.hpp +++ b/components/chatlist.hpp @@ -2,7 +2,7 @@ #include #include #include -#include "../discord/snowflake.hpp" +#include "discord/snowflake.hpp" class ChatList : public Gtk::ScrolledWindow { public: @@ -21,7 +21,7 @@ public: void SetFailedByNonce(const std::string &nonce); std::vector GetRecentAuthors(); void SetSeparateAll(bool separate); - void SetUsePinnedMenu(); // i think i need a better way to do menus + void SetUsePinnedMenu(); // i think i need a better way to do menus void ActuallyRemoveMessage(Snowflake id); // perhaps not the best method name private: @@ -101,6 +101,15 @@ inline void ChatList::SetMessages(Iter begin, Iter end) { template inline void ChatList::PrependMessages(Iter begin, Iter end) { + const auto old_upper = get_vadjustment()->get_upper(); + const auto old_value = get_vadjustment()->get_value(); for (Iter it = begin; it != end; it++) ProcessNewMessage(*it, true); + // force everything to process before getting new values + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(); + const auto new_upper = get_vadjustment()->get_upper(); + if (old_value == 0.0 && (new_upper - old_upper) > 0.0) + get_vadjustment()->set_value(new_upper - old_upper); + // this isn't ideal } -- cgit v1.2.3