diff --git a/crates/agent/src/agent_panel.rs b/crates/agent/src/agent_panel.rs index 4e3e0bae2b3d2aae2f794fcecea76b5cda9b2a41..d1f0e816f54e7608b4e61abe2ecb30619a4a4a75 100644 --- a/crates/agent/src/agent_panel.rs +++ b/crates/agent/src/agent_panel.rs @@ -567,6 +567,15 @@ impl AgentPanel { menu = menu.header("Recently Opened"); for entry in recently_opened.iter() { + if let RecentEntry::Context(context) = entry { + if context.read(cx).path().is_none() { + log::error!( + "bug: text thread in recent history list was never saved" + ); + continue; + } + } + let summary = entry.summary(cx); menu = menu.entry_with_end_slot_on_hover( @@ -1290,14 +1299,26 @@ impl AgentPanel { let new_is_history = matches!(new_view, ActiveView::History); match &self.active_view { - ActiveView::Thread { thread, .. } => self.history_store.update(cx, |store, cx| { + ActiveView::Thread { thread, .. } => { if let Some(thread) = thread.upgrade() { if thread.read(cx).is_empty() { let id = thread.read(cx).id().clone(); - store.remove_recently_opened_thread(id, cx); + self.history_store.update(cx, |store, cx| { + store.remove_recently_opened_thread(id, cx); + }); } } - }), + } + ActiveView::PromptEditor { context_editor, .. } => { + let context = context_editor.read(cx).context(); + // When switching away from an unsaved text thread, delete its entry. + if context.read(cx).path().is_none() { + let context = context.clone(); + self.history_store.update(cx, |store, cx| { + store.remove_recently_opened_entry(&RecentEntry::Context(context), cx); + }); + } + } _ => {} }