Don't lose focus on default panel state

This commit is contained in:
Conrad Irwin 2024-01-13 14:32:24 -07:00
parent eafe0944e0
commit c2ff9fe2da

View file

@ -59,6 +59,7 @@ pub struct ChatPanel {
subscriptions: Vec<gpui::Subscription>, subscriptions: Vec<gpui::Subscription>,
is_scrolled_to_bottom: bool, is_scrolled_to_bottom: bool,
markdown_data: HashMap<ChannelMessageId, RichText>, markdown_data: HashMap<ChannelMessageId, RichText>,
focus_handle: FocusHandle,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -126,6 +127,7 @@ impl ChatPanel {
active: false, active: false,
width: None, width: None,
markdown_data: Default::default(), markdown_data: Default::default(),
focus_handle: cx.focus_handle(),
}; };
let mut old_dock_position = this.position(cx); let mut old_dock_position = this.position(cx);
@ -490,6 +492,7 @@ impl EventEmitter<Event> for ChatPanel {}
impl Render for ChatPanel { impl Render for ChatPanel {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
v_stack() v_stack()
.track_focus(&self.focus_handle)
.full() .full()
.on_action(cx.listener(Self::send)) .on_action(cx.listener(Self::send))
.child( .child(
@ -559,7 +562,11 @@ impl Render for ChatPanel {
impl FocusableView for ChatPanel { impl FocusableView for ChatPanel {
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle { fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
self.message_editor.read(cx).focus_handle(cx) if self.active_chat.is_some() {
self.message_editor.read(cx).focus_handle(cx)
} else {
self.focus_handle.clone()
}
} }
} }