aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp23
1 files changed, 14 insertions, 9 deletions
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() {