sidebar: Improve hover in history view thread items (#54370) (cherry-pick to preview) (#54377)

zed-zippy[bot] and Danilo Leal created

Cherry-pick of #54370 to preview

----
This PR improves the hover state in thread items within the history view
by making them more stable. There were other thread events calling a
refresh, which would clear the hover state even though I'd still be
hovering the item, making the buttons that only appear on hover feel
unstable and disappear.

Release Notes:

- Agent: Improve hover state stability on thread items within the
sidebar's history view.

Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>

Change summary

crates/agent_ui/src/threads_archive_view.rs | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

Detailed changes

crates/agent_ui/src/threads_archive_view.rs 🔗

@@ -325,9 +325,7 @@ impl ThreadsArchiveView {
         self.list_state.reset(items.len());
         self.items = items;
 
-        if !preserve {
-            self.hovered_index = None;
-        } else if let Some(ix) = self.hovered_index {
+        if let Some(ix) = self.hovered_index {
             if ix >= self.items.len() || !self.is_selectable_item(ix) {
                 self.hovered_index = None;
             }
@@ -649,12 +647,15 @@ impl ThreadsArchiveView {
                     .focused(is_focused)
                     .hovered(is_hovered)
                     .on_hover(cx.listener(move |this, is_hovered, _window, cx| {
-                        if *is_hovered {
-                            this.hovered_index = Some(ix);
-                        } else if this.hovered_index == Some(ix) {
-                            this.hovered_index = None;
+                        let previously_hovered = this.hovered_index;
+                        this.hovered_index = if *is_hovered {
+                            Some(ix)
+                        } else {
+                            previously_hovered.filter(|&i| i != ix)
+                        };
+                        if this.hovered_index != previously_hovered {
+                            cx.notify();
                         }
-                        cx.notify();
                     }));
 
                 if is_restoring {