diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index d7299ca6b59b1f710666cba3ff273eac06e9a58e..11a82aac4b6c6b1ce067fc66ed7f548366de7683 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -119,6 +119,7 @@ pub struct AssistantPanel { width: Option, height: Option, active_editor_index: Option, + prev_active_editor_index: Option, editors: Vec>, saved_conversations: Vec, saved_conversations_list_state: UniformListState, @@ -176,6 +177,7 @@ impl AssistantPanel { }); let mut this = Self { active_editor_index: Default::default(), + prev_active_editor_index: Default::default(), editors: Default::default(), saved_conversations, saved_conversations_list_state: Default::default(), @@ -240,6 +242,7 @@ impl AssistantPanel { } fn set_active_editor_index(&mut self, index: Option, cx: &mut ViewContext) { + self.prev_active_editor_index = self.active_editor_index; self.active_editor_index = index; if let Some(editor) = self.active_editor() { let editor = editor.read(cx).editor.clone(); @@ -350,7 +353,11 @@ impl AssistantPanel { .mouse::(0) .with_cursor_style(CursorStyle::PointingHand) .on_click(MouseButton::Left, |_, this: &mut Self, cx| { - this.set_active_editor_index(None, cx); + if this.active_editor().is_some() { + this.set_active_editor_index(None, cx); + } else { + this.set_active_editor_index(this.prev_active_editor_index, cx); + } }) }