diff --git a/gpui/src/views/select.rs b/gpui/src/views/select.rs index cd7d912667..b9e099a75c 100644 --- a/gpui/src/views/select.rs +++ b/gpui/src/views/select.rs @@ -75,6 +75,10 @@ impl Select { self.is_open = false; cx.notify(); } + + pub fn selected_index(&self) -> usize { + self.selected_item_ix + } } impl Entity for Select { diff --git a/zed/src/chat_panel.rs b/zed/src/chat_panel.rs index bf9d65327e..1b757d3ea4 100644 --- a/zed/src/chat_panel.rs +++ b/zed/src/chat_panel.rs @@ -99,6 +99,18 @@ impl ChatPanel { this.init_active_channel(cx); }) .detach(); + cx.observe(&this.channel_select, |this, channel_select, cx| { + let selected_ix = channel_select.read(cx).selected_index(); + let selected_channel = this.channel_list.update(cx, |channel_list, cx| { + let available_channels = channel_list.available_channels()?; + let channel_id = available_channels.get(selected_ix)?.id; + channel_list.get_channel(channel_id, cx) + }); + if let Some(selected_channel) = selected_channel { + this.set_active_channel(selected_channel, cx); + } + }) + .detach(); this }