From cd663ba4dee4c15413d26a2cd6ce9c191f6fabf3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 28 May 2021 18:37:58 +0200 Subject: Properly scroll item when fetching previous messages and new messages in body in matrix --- src/Body.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Body.cpp b/src/Body.cpp index 3e05a78..3acaf3b 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -265,21 +265,26 @@ namespace QuickMedia { // TODO: Optimize by resizing |items| before insert void Body::insert_items_by_timestamps(BodyItems new_items) { - int new_selected_item = selected_item; + BodyItem *selected_body_item = nullptr; + if(selected_item >= 0 && selected_item < (int)items.size()) + selected_body_item = items[selected_item].get(); for(auto &new_item : new_items) { insert_item_by_timestamp(new_item); - if(attach_side == AttachSide::TOP) { - new_selected_item = get_previous_visible_item(new_selected_item); - } else { - new_selected_item = get_next_visible_item(new_selected_item); - } } - selected_item = new_selected_item; clamp_selection(); - items_set_dirty(); - prev_selected_item = selected_item; + items_set_dirty(); // TODO: Apply this now, otherwise the below code wont work + + if(!selected_body_item) + return; + + for(size_t i = 0; i < items.size(); ++i) { + if(selected_body_item == items[i].get()) { + set_selected_item(i); + break; + } + } } void Body::clear_cache() { -- cgit v1.2.3