chore: stabilize element ids and overlay focus tracking
This commit is contained in:
@@ -7,7 +7,7 @@ use gpui::{
|
||||
ParentElement as _, Render, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
};
|
||||
use helpers::apply_appearance_mode;
|
||||
use settings::SettingsStore;
|
||||
use settings::{AppearanceMode, SettingsStore};
|
||||
use signed_state::{Backend, BackendEvent};
|
||||
use ui::common::{h_flex, v_flex};
|
||||
use ui::icons::IconRole;
|
||||
@@ -28,7 +28,7 @@ use crate::titlebar::{
|
||||
pub struct AppRoot {
|
||||
panels: Entity<PanelStack>,
|
||||
titlebar: Entity<TitlebarView>,
|
||||
passphrase: Option<Entity<PassphraseDialog>>,
|
||||
appearance: AppearanceMode,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
@@ -66,9 +66,12 @@ impl AppRoot {
|
||||
},
|
||||
));
|
||||
|
||||
subscriptions.push(cx.observe(&settings, |_this, store, cx| {
|
||||
let settings = store.read(cx).settings().clone();
|
||||
apply_appearance_mode(settings.appearance, cx);
|
||||
subscriptions.push(cx.observe(&settings, |this, store, cx| {
|
||||
let appearance = store.read(cx).settings().appearance;
|
||||
if appearance != this.appearance {
|
||||
this.appearance = appearance;
|
||||
apply_appearance_mode(appearance, cx);
|
||||
}
|
||||
}));
|
||||
|
||||
window.defer(cx, move |window, cx| {
|
||||
@@ -78,20 +81,18 @@ impl AppRoot {
|
||||
Self::reset_to_explore(&app, window, cx);
|
||||
});
|
||||
|
||||
let appearance = settings.read(cx).settings().appearance;
|
||||
|
||||
Self {
|
||||
panels,
|
||||
titlebar,
|
||||
passphrase: None,
|
||||
appearance,
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
fn open_passphrase(&mut self, cx: &mut Context<Self>) {
|
||||
if self.passphrase.is_some() {
|
||||
return;
|
||||
}
|
||||
let dialog = PassphraseDialog::new(cx);
|
||||
self.passphrase = Some(dialog.clone());
|
||||
cx.open_dialog(dialog);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ impl RepoFilter {
|
||||
}
|
||||
|
||||
pub(super) fn render_card(
|
||||
ix: usize,
|
||||
announcement: &Announcement,
|
||||
last_activity: Option<Timestamp>,
|
||||
announcements: &[Announcement],
|
||||
@@ -98,7 +97,7 @@ pub(super) fn render_card(
|
||||
});
|
||||
|
||||
v_flex()
|
||||
.id(ix)
|
||||
.id(SharedString::from(format!("repo-card:{}", announcement.id)))
|
||||
.flex_1()
|
||||
.h_full()
|
||||
.min_w_0()
|
||||
@@ -113,6 +112,7 @@ pub(super) fn render_card(
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.text_sm()
|
||||
.font_semibold()
|
||||
|
||||
@@ -294,7 +294,6 @@ impl Render for ExploreView {
|
||||
};
|
||||
let activity = last_activity.get(&announcement.addr()).copied();
|
||||
cards.push(render_card(
|
||||
ix,
|
||||
announcement,
|
||||
activity,
|
||||
&announcements,
|
||||
|
||||
@@ -127,7 +127,15 @@ pub(crate) fn sidebar_section(
|
||||
.picture(profile.picture())
|
||||
.small(),
|
||||
)
|
||||
.child(div().text_base().text_ellipsis().child(name))
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.whitespace_nowrap()
|
||||
.text_base()
|
||||
.text_ellipsis()
|
||||
.child(name),
|
||||
)
|
||||
.into_any_element()
|
||||
})),
|
||||
)
|
||||
|
||||
@@ -182,8 +182,7 @@ impl Render for IssuesView {
|
||||
|
||||
let rows = visible_issues
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(ix, &issue_ix)| {
|
||||
.filter_map(|&issue_ix| {
|
||||
// The store re-read per frame can shrink below a captured index.
|
||||
let issue = store.read(cx).issues.get(issue_ix)?;
|
||||
let profile = directory.read(cx).profile(&issue.pubkey, cx);
|
||||
@@ -210,7 +209,7 @@ impl Render for IssuesView {
|
||||
};
|
||||
|
||||
Some(EventRow {
|
||||
id: ix.into(),
|
||||
id: SharedString::from(format!("issue:{id_hex}")).into(),
|
||||
status,
|
||||
title: issue.activity_subject().into(),
|
||||
author: profile.name(),
|
||||
|
||||
@@ -295,8 +295,7 @@ impl Render for PullRequestsView {
|
||||
|
||||
let rows = visible
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(ix, &pr_ix)| {
|
||||
.filter_map(|&pr_ix| {
|
||||
// The store re-read per frame can shrink below a captured index.
|
||||
let pr = store.read(cx).pull_requests.get(pr_ix)?;
|
||||
let profile = directory.read(cx).profile(&pr.pubkey, cx);
|
||||
@@ -332,7 +331,7 @@ impl Render for PullRequestsView {
|
||||
};
|
||||
|
||||
Some(EventRow {
|
||||
id: ix.into(),
|
||||
id: SharedString::from(format!("pr:{id_hex}")).into(),
|
||||
status,
|
||||
title: pr.activity_subject().into(),
|
||||
author: profile.name(),
|
||||
|
||||
@@ -559,11 +559,9 @@ fn render_pane_row(
|
||||
|
||||
impl Render for DiffPane {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
if self.diff.is_none() {
|
||||
let Some(diff) = self.diff.as_ref() else {
|
||||
return EmptyState::centered("No changes");
|
||||
}
|
||||
|
||||
let diff = self.diff.as_ref().expect("diff checked above");
|
||||
};
|
||||
|
||||
if diff.files.is_empty() {
|
||||
return EmptyState::centered("No files changed");
|
||||
@@ -822,7 +820,9 @@ impl CommitDiffView {
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(Avatar::new(name.clone()).name(name.clone()).small())
|
||||
.child(div().truncate().text_ellipsis().child(name))
|
||||
.child(
|
||||
div().min_w_0().truncate().text_ellipsis().child(name),
|
||||
)
|
||||
.into_any_element(),
|
||||
)
|
||||
})
|
||||
@@ -849,6 +849,7 @@ impl CommitDiffView {
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.text_ellipsis()
|
||||
.truncate()
|
||||
.child(SharedString::from(commit.id.clone())),
|
||||
@@ -863,6 +864,7 @@ impl CommitDiffView {
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.text_ellipsis()
|
||||
.truncate()
|
||||
.child(SharedString::from(parent.clone())),
|
||||
|
||||
@@ -340,6 +340,7 @@ impl RepoFilesView {
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.text_xs()
|
||||
.font_medium()
|
||||
.text_ellipsis()
|
||||
|
||||
@@ -211,7 +211,13 @@ pub(super) fn fork_row(
|
||||
.text_base()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(Icon::named(IconRole::GitBranch).small())
|
||||
.child(div().whitespace_nowrap().text_ellipsis().child(label));
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.whitespace_nowrap()
|
||||
.text_ellipsis()
|
||||
.child(label),
|
||||
);
|
||||
|
||||
Some(if clickable {
|
||||
row.id("fork-upstream")
|
||||
|
||||
@@ -390,7 +390,7 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -509,7 +509,7 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
fn apply_repo_data(&mut self, data: RepoData, window: &mut Window, cx: &mut Context<Self>) {
|
||||
@@ -609,7 +609,7 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
fn switch_ref<T>(&mut self, kind: RefKind, name: T, window: &mut Window, cx: &mut Context<Self>)
|
||||
@@ -684,7 +684,7 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
fn reload_worktree(&mut self, cx: &mut Context<Self>) {
|
||||
@@ -727,7 +727,7 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
/// Refresh the file explorer and previews after the mirror caught up with the remote.
|
||||
@@ -758,6 +758,12 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
/// Reaps finished tasks, then queues another.
|
||||
fn push_task(&mut self, task: Task<Result<(), Error>>) {
|
||||
self.tasks.retain(|task| !task.is_ready());
|
||||
self.tasks.push(task);
|
||||
}
|
||||
|
||||
@@ -766,7 +772,7 @@ impl RepoDetailView {
|
||||
cx.notify();
|
||||
|
||||
let task = self.store.update(cx, |store, cx| store.push_repository(cx));
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
fn sync_notification_tag(addr: &RepoAddr) -> SharedString {
|
||||
@@ -866,7 +872,7 @@ impl RepoDetailView {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
fn reset_remote(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
@@ -932,7 +938,7 @@ impl RepoDetailView {
|
||||
let task = self
|
||||
.store
|
||||
.update(cx, |store, cx| store.delete_repository(cx));
|
||||
self.tasks.push(task);
|
||||
self.push_task(task);
|
||||
}
|
||||
|
||||
fn render_files_tab(&self, cx: &App) -> AnyElement {
|
||||
@@ -1122,7 +1128,13 @@ impl RepoDetailView {
|
||||
.text_sm()
|
||||
.font_semibold()
|
||||
.child(avatar)
|
||||
.child(name),
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.whitespace_nowrap()
|
||||
.text_ellipsis()
|
||||
.child(name),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
|
||||
@@ -226,7 +226,6 @@ pub fn commit_list(
|
||||
let on_click = on_click.clone();
|
||||
let row_commit = commit.clone();
|
||||
commit_row(
|
||||
ix,
|
||||
&commit,
|
||||
action,
|
||||
move |window, cx| on_click(&row_commit, window, cx),
|
||||
@@ -244,14 +243,13 @@ pub fn commit_list(
|
||||
|
||||
/// One copyable commit summary row: id, subject, author, and age.
|
||||
pub(crate) fn commit_row(
|
||||
ix: usize,
|
||||
commit: &FileCommit,
|
||||
action: Option<AnyElement>,
|
||||
on_click: impl Fn(&mut Window, &mut gpui::App) + 'static,
|
||||
cx: &gpui::App,
|
||||
) -> gpui::AnyElement {
|
||||
h_flex()
|
||||
.id(ix)
|
||||
.id(commit.id.clone())
|
||||
.px_4()
|
||||
.h(px(COMMIT_ROW_HEIGHT))
|
||||
.w_full()
|
||||
|
||||
@@ -211,7 +211,7 @@ impl Render for RepositorySwitcher {
|
||||
|
||||
Some(
|
||||
h_flex()
|
||||
.id(("repo-switcher-entry", index))
|
||||
.id(entry.key.clone())
|
||||
.role(Role::MenuItem)
|
||||
.w_full()
|
||||
.h(row_height)
|
||||
|
||||
Reference in New Issue
Block a user