Diagnostics pane was not focusable with the mouse (#2506)

fixes
https://linear.app/zed-industries/issue/Z-1432/cant-cmd-w-an-empty-diagnostics-in-a-split-pane

Release Notes:

* Fixed a bug where the diagnostics pane could not be focused or closed
in certain circumstances.
This commit is contained in:
Mikayla Maki 2023-05-22 12:44:39 -07:00 committed by GitHub
commit dcb987ba9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 10 deletions

View file

@ -33,7 +33,7 @@ use theme::ThemeSettings;
use util::TryFutureExt; use util::TryFutureExt;
use workspace::{ use workspace::{
item::{BreadcrumbText, Item, ItemEvent, ItemHandle}, item::{BreadcrumbText, Item, ItemEvent, ItemHandle},
ItemNavHistory, Pane, ToolbarItemLocation, Workspace, ItemNavHistory, Pane, PaneBackdrop, ToolbarItemLocation, Workspace,
}; };
actions!(diagnostics, [Deploy]); actions!(diagnostics, [Deploy]);
@ -90,10 +90,14 @@ impl View for ProjectDiagnosticsEditor {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if self.path_states.is_empty() { if self.path_states.is_empty() {
let theme = &theme::current(cx).project_diagnostics; let theme = &theme::current(cx).project_diagnostics;
PaneBackdrop::new(
cx.view_id(),
Label::new("No problems in workspace", theme.empty_message.clone()) Label::new("No problems in workspace", theme.empty_message.clone())
.aligned() .aligned()
.contained() .contained()
.with_style(theme.container) .with_style(theme.container)
.into_any(),
)
.into_any() .into_any()
} else { } else {
ChildView::new(&self.editor, cx).into_any() ChildView::new(&self.editor, cx).into_any()
@ -101,8 +105,9 @@ impl View for ProjectDiagnosticsEditor {
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
if cx.is_self_focused() && !self.path_states.is_empty() { dbg!("Focus in");
cx.focus(&self.editor); if dbg!(cx.is_self_focused()) && dbg!(!self.path_states.is_empty()) {
dbg!(cx.focus(&self.editor));
} }
} }
@ -161,7 +166,12 @@ impl ProjectDiagnosticsEditor {
editor.set_vertical_scroll_margin(5, cx); editor.set_vertical_scroll_margin(5, cx);
editor editor
}); });
cx.subscribe(&editor, |_, _, event, cx| cx.emit(event.clone())) cx.subscribe(&editor, |this, _, event, cx| {
cx.emit(event.clone());
if event == &editor::Event::Focused && this.path_states.is_empty() {
cx.focus_self()
}
})
.detach(); .detach();
let project = project_handle.read(cx); let project = project_handle.read(cx);

View file

@ -7207,6 +7207,7 @@ pub enum Event {
BufferEdited, BufferEdited,
Edited, Edited,
Reparsed, Reparsed,
Focused,
Blurred, Blurred,
DirtyChanged, DirtyChanged,
Saved, Saved,
@ -7258,8 +7259,10 @@ impl View for Editor {
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
dbg!("Editor Focus in");
if cx.is_self_focused() { if cx.is_self_focused() {
let focused_event = EditorFocused(cx.handle()); let focused_event = EditorFocused(cx.handle());
cx.emit(Event::Focused);
cx.emit_global(focused_event); cx.emit_global(focused_event);
} }
if let Some(rename) = self.pending_rename.as_ref() { if let Some(rename) = self.pending_rename.as_ref() {