Skip to content

Commit 0029245

Browse files
danilo-lealagu-z
andauthored
agent: Show delete thread icon buttons on hover/focus (#30370)
This PR's main goal is to show the delete thread button when the list item is either focused or hovered. In order to do that, we ended up refactoring (i.e., merging) the `PastThread` and `PastContext` elements into a single `HistoryElementEntry` that already matches to the entry type (i.e., context or thread). Release Notes: - agent: Simplify the UI by showing the delete thread icon button only on hover or focus. --------- Co-authored-by: Agus Zubiaga <[email protected]>
1 parent 49c01c6 commit 0029245

File tree

3 files changed

+186
-208
lines changed

3 files changed

+186
-208
lines changed

crates/agent/src/agent_panel.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ use zed_llm_client::UsageLimit;
5555
use crate::active_thread::{self, ActiveThread, ActiveThreadEvent};
5656
use crate::agent_configuration::{AgentConfiguration, AssistantConfigurationEvent};
5757
use crate::agent_diff::AgentDiff;
58-
use crate::history_store::{HistoryEntry, HistoryStore, RecentEntry};
58+
use crate::history_store::{HistoryStore, RecentEntry};
5959
use crate::message_editor::{MessageEditor, MessageEditorEvent};
6060
use crate::thread::{Thread, ThreadError, ThreadId, TokenUsageRatio};
61-
use crate::thread_history::{EntryTimeFormat, PastContext, PastThread, ThreadHistory};
61+
use crate::thread_history::{HistoryEntryElement, ThreadHistory};
6262
use crate::thread_store::ThreadStore;
6363
use crate::ui::AgentOnboardingModal;
6464
use crate::{
@@ -356,6 +356,7 @@ pub struct AgentPanel {
356356
previous_view: Option<ActiveView>,
357357
history_store: Entity<HistoryStore>,
358358
history: Entity<ThreadHistory>,
359+
hovered_recent_history_item: Option<usize>,
359360
assistant_dropdown_menu_handle: PopoverMenuHandle<ContextMenu>,
360361
assistant_navigation_menu_handle: PopoverMenuHandle<ContextMenu>,
361362
assistant_navigation_menu: Option<Entity<ContextMenu>>,
@@ -696,6 +697,7 @@ impl AgentPanel {
696697
previous_view: None,
697698
history_store: history_store.clone(),
698699
history: cx.new(|cx| ThreadHistory::new(weak_self, history_store, window, cx)),
700+
hovered_recent_history_item: None,
699701
assistant_dropdown_menu_handle: PopoverMenuHandle::default(),
700702
assistant_navigation_menu_handle: PopoverMenuHandle::default(),
701703
assistant_navigation_menu: None,
@@ -2212,7 +2214,7 @@ impl AgentPanel {
22122214
.border_b_1()
22132215
.border_color(cx.theme().colors().border_variant)
22142216
.child(
2215-
Label::new("Past Interactions")
2217+
Label::new("Recent")
22162218
.size(LabelSize::Small)
22172219
.color(Color::Muted),
22182220
)
@@ -2237,18 +2239,20 @@ impl AgentPanel {
22372239
v_flex()
22382240
.gap_1()
22392241
.children(
2240-
recent_history.into_iter().map(|entry| {
2242+
recent_history.into_iter().enumerate().map(|(index, entry)| {
22412243
// TODO: Add keyboard navigation.
2242-
match entry {
2243-
HistoryEntry::Thread(thread) => {
2244-
PastThread::new(thread, cx.entity().downgrade(), false, vec![], EntryTimeFormat::DateAndTime)
2245-
.into_any_element()
2246-
}
2247-
HistoryEntry::Context(context) => {
2248-
PastContext::new(context, cx.entity().downgrade(), false, vec![], EntryTimeFormat::DateAndTime)
2249-
.into_any_element()
2250-
}
2251-
}
2244+
let is_hovered = self.hovered_recent_history_item == Some(index);
2245+
HistoryEntryElement::new(entry.clone(), cx.entity().downgrade())
2246+
.hovered(is_hovered)
2247+
.on_hover(cx.listener(move |this, is_hovered, _window, cx| {
2248+
if *is_hovered {
2249+
this.hovered_recent_history_item = Some(index);
2250+
} else if this.hovered_recent_history_item == Some(index) {
2251+
this.hovered_recent_history_item = None;
2252+
}
2253+
cx.notify();
2254+
}))
2255+
.into_any_element()
22522256
}),
22532257
)
22542258
)

0 commit comments

Comments
 (0)