From 103fc1927ead39f0df6132b4e1ad7f2c50a4db65 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Thu, 19 Jan 2023 13:27:24 +0530 Subject: [PATCH] room-history: Prevent scroll when contextual menu is shown closes GNOME/fractal#937 --- src/session/content/room_history/item_row.rs | 5 ++++- src/session/content/room_history/mod.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/session/content/room_history/item_row.rs b/src/session/content/room_history/item_row.rs index 66fae7f5..4fc3433b 100644 --- a/src/session/content/room_history/item_row.rs +++ b/src/session/content/room_history/item_row.rs @@ -99,6 +99,7 @@ mod imp { if let Some(event) = obj.item().and_then(|item| item.downcast::().ok()) { let room_history = obj.room_history(); let popover = room_history.item_context_menu().to_owned(); + room_history.set_sticky(false); if let Some(list_item) = obj.parent() { list_item.add_css_class("has-open-popup"); @@ -106,7 +107,9 @@ mod imp { let cell: Rc>> = Rc::new(RefCell::new(None)); let signal_id = popover.connect_closed( - clone!(@weak list_item, @strong cell => move |popover| { + clone!(@weak list_item, @strong cell, @weak room_history => move |popover| { + room_history.enable_sticky_mode(); + list_item.remove_css_class("has-open-popup"); if let Some(signal_id) = cell.take() { diff --git a/src/session/content/room_history/mod.rs b/src/session/content/room_history/mod.rs index 9e0472bc..c723c514 100644 --- a/src/session/content/room_history/mod.rs +++ b/src/session/content/room_history/mod.rs @@ -895,6 +895,14 @@ impl RoomHistory { .emit_by_name::("scroll-child", &[>k::ScrollType::End, &false]); } + /// Set `RoomHistory` to stick to the bottom based on scrollbar position + pub fn enable_sticky_mode(&self) { + let imp = self.imp(); + let adj = imp.listview.vadjustment().unwrap(); + let is_at_bottom = adj.value() + adj.page_size() == adj.upper(); + self.set_sticky(is_at_bottom); + } + fn try_again(&self) { self.start_loading(); }