Fix project diff focus (#24691)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2025-02-11 17:40:40 -07:00 committed by GitHub
parent 9a9fdce253
commit f5fd3d98ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -335,6 +335,22 @@ impl ProjectDiff {
cx, cx,
); );
}); });
if self.multibuffer.read(cx).is_empty()
&& self
.editor
.read(cx)
.focus_handle(cx)
.contains_focused(window, cx)
{
self.focus_handle.focus(window);
} else if self.focus_handle.contains_focused(window, cx)
&& !self.multibuffer.read(cx).is_empty()
{
self.editor.update(cx, |editor, cx| {
editor.focus_handle(cx).focus(window);
editor.move_to_beginning(&Default::default(), window, cx);
});
}
if self.pending_scroll.as_ref() == Some(&path_key) { if self.pending_scroll.as_ref() == Some(&path_key) {
self.scroll_to_path(path_key, window, cx); self.scroll_to_path(path_key, window, cx);
} }
@ -365,8 +381,12 @@ impl ProjectDiff {
impl EventEmitter<EditorEvent> for ProjectDiff {} impl EventEmitter<EditorEvent> for ProjectDiff {}
impl Focusable for ProjectDiff { impl Focusable for ProjectDiff {
fn focus_handle(&self, _: &App) -> FocusHandle { fn focus_handle(&self, cx: &App) -> FocusHandle {
self.focus_handle.clone() if self.multibuffer.read(cx).is_empty() {
self.focus_handle.clone()
} else {
self.editor.focus_handle(cx)
}
} }
} }
@ -537,22 +557,17 @@ impl Item for ProjectDiff {
impl Render for ProjectDiff { impl Render for ProjectDiff {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let is_empty = self.multibuffer.read(cx).is_empty(); let is_empty = self.multibuffer.read(cx).is_empty();
if is_empty {
div() div()
.bg(cx.theme().colors().editor_background) .track_focus(&self.focus_handle)
.flex() .bg(cx.theme().colors().editor_background)
.items_center() .flex()
.justify_center() .items_center()
.size_full() .justify_center()
.child(Label::new("No uncommitted changes")) .size_full()
} else { .when(is_empty, |el| {
div() el.child(Label::new("No uncommitted changes"))
.bg(cx.theme().colors().editor_background) })
.flex() .when(!is_empty, |el| el.child(self.editor.clone()))
.items_center()
.justify_center()
.size_full()
.child(self.editor.clone())
}
} }
} }