perf: reuse rendered elements across repaints
This commit is contained in:
@@ -2,10 +2,17 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add a confirmation dialog before deleting a repository
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Opening a repository no longer runs a forced checkout of its worktree
|
- Opening a repository no longer runs a forced checkout of its worktree
|
||||||
- Deleting a repository now waits until its deletion events are accepted by a relay
|
- Deleting a repository now waits until its deletion events are accepted by a relay
|
||||||
|
- Keep the Explore list at its scroll position across background refreshes, a new search or filter still starts at the top
|
||||||
|
- Reuse the rendered file tree, commit diffs, README previews and split pane instead of rebuilding them on every repaint
|
||||||
|
- Truncate long tab and file tree labels with an ellipsis instead of letting them widen their row
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
@@ -23,6 +30,9 @@
|
|||||||
- Fix profiles staying stuck after a failed database query, and a repository view showing "Cloning repository" forever when no announcement is found
|
- Fix profiles staying stuck after a failed database query, and a repository view showing "Cloning repository" forever when no announcement is found
|
||||||
- Fix commit patch downloads failing silently and dismissed pull request alerts staying on screen
|
- Fix commit patch downloads failing silently and dismissed pull request alerts staying on screen
|
||||||
- Fix busy dialogs being dismissed by Escape or a backdrop click while their task was still running
|
- Fix busy dialogs being dismissed by Escape or a backdrop click while their task was still running
|
||||||
|
- Fix text typed into a field under a panel appearing up to a quarter second late
|
||||||
|
- Fix an open dialog taking keyboard focus back from the command palette or a toast button on every repaint
|
||||||
|
- Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal
|
||||||
|
|
||||||
## v0.2.0 - 2026/10/21
|
## v0.2.0 - 2026/10/21
|
||||||
|
|
||||||
|
|||||||
@@ -75,18 +75,18 @@ impl ExploreView {
|
|||||||
|
|
||||||
let search_subscription = cx.subscribe(&search, |this, _search, event, cx| {
|
let search_subscription = cx.subscribe(&search, |this, _search, event, cx| {
|
||||||
if matches!(event, InputStateEvent::TextChanged) {
|
if matches!(event, InputStateEvent::TextChanged) {
|
||||||
this.rebuild_rows(cx);
|
this.rebuild_rows(false, cx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let store_subscription = cx.observe(&store, |this, _store, cx| {
|
let store_subscription = cx.observe(&store, |this, _store, cx| {
|
||||||
this.rebuild_rows(cx);
|
this.rebuild_rows(true, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
// The root and the stack are still being updated while this view is built.
|
// The root and the stack are still being updated while this view is built.
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
if let Err(error) = weak.update(cx, |this, cx| {
|
if let Err(error) = weak.update(cx, |this, cx| {
|
||||||
this.rebuild_rows(cx);
|
this.rebuild_rows(false, cx);
|
||||||
this.watch_stack(cx);
|
this.watch_stack(cx);
|
||||||
}) {
|
}) {
|
||||||
log::warn!("failed to set up the explore panel: {error}");
|
log::warn!("failed to set up the explore panel: {error}");
|
||||||
@@ -107,7 +107,8 @@ impl ExploreView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rebuild_rows(&mut self, cx: &mut Context<Self>) {
|
/// `anchor` keeps the scroll position while the row count is unchanged.
|
||||||
|
fn rebuild_rows(&mut self, anchor: bool, cx: &mut Context<Self>) {
|
||||||
let filter = self.filter;
|
let filter = self.filter;
|
||||||
let query = self.search.read(cx).value().to_string();
|
let query = self.search.read(cx).value().to_string();
|
||||||
let store = self.store.read(cx);
|
let store = self.store.read(cx);
|
||||||
@@ -125,7 +126,11 @@ impl ExploreView {
|
|||||||
directory.track(owners, cx);
|
directory.track(owners, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.scroll_handle.reset(self.item_count());
|
let count = self.item_count();
|
||||||
|
if !anchor || count != self.scroll_handle.item_count() {
|
||||||
|
self.scroll_handle.reset(count);
|
||||||
|
}
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +228,7 @@ impl ExploreView {
|
|||||||
.on_change(move |filter, _, cx| {
|
.on_change(move |filter, _, cx| {
|
||||||
if let Err(error) = weak.update(cx, |this, cx| {
|
if let Err(error) = weak.update(cx, |this, cx| {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.rebuild_rows(cx);
|
this.rebuild_rows(false, cx);
|
||||||
}) {
|
}) {
|
||||||
log::warn!("failed to change explore filter: {error}");
|
log::warn!("failed to change explore filter: {error}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,16 +33,18 @@ pub struct IssueDetailView {
|
|||||||
impl IssueDetailView {
|
impl IssueDetailView {
|
||||||
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
|
pub fn new(store: Entity<RepoStore>, issue_id: EventId, cx: &mut Context<Self>) -> Self {
|
||||||
let comment_input = InputState::builder().multiline().build(cx);
|
let comment_input = InputState::builder().multiline().build(cx);
|
||||||
|
let directory = ProfileDirectory::new(cx);
|
||||||
|
let weak = cx.entity().downgrade();
|
||||||
|
|
||||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||||
this.track_participants(cx);
|
this.track_participants(cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
|
||||||
let directory = ProfileDirectory::new(cx);
|
|
||||||
let weak = cx.entity().downgrade();
|
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
log_dropped(weak.update(cx, |this, cx| this.track_participants(cx)));
|
log_dropped(weak.update(cx, |this, cx| {
|
||||||
|
this.track_participants(cx);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||||
SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div,
|
SharedString, Styled as _, Subscription, UniformListScrollHandle, WeakEntity, Window, div,
|
||||||
@@ -12,18 +13,17 @@ use ui::button::Button;
|
|||||||
use ui::common::v_flex;
|
use ui::common::v_flex;
|
||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::Panel;
|
||||||
|
use ui::layout::root::RootContext as _;
|
||||||
use ui::segmented::{Segmented, SegmentedOption};
|
use ui::segmented::{Segmented, SegmentedOption};
|
||||||
use ui::theme::ActiveTheme as _;
|
use ui::theme::ActiveTheme as _;
|
||||||
use utils::relative_time;
|
use utils::relative_time;
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use self::detail::IssueDetailView;
|
use self::detail::IssueDetailView;
|
||||||
use crate::app::AppRoot;
|
use crate::app::AppRoot;
|
||||||
|
use crate::issues::new_issue::NewIssueDialog;
|
||||||
use crate::repo::helpers::short_id;
|
use crate::repo::helpers::short_id;
|
||||||
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar};
|
use crate::shared::event_list::{EventHandler, EventList, EventRow, filter_toolbar};
|
||||||
use crate::shared::log_dropped;
|
use crate::shared::{log_dropped, panels};
|
||||||
use crate::shared::panels;
|
|
||||||
|
|
||||||
pub mod detail;
|
pub mod detail;
|
||||||
pub(crate) mod helpers;
|
pub(crate) mod helpers;
|
||||||
@@ -32,7 +32,6 @@ pub mod new_issue;
|
|||||||
pub struct IssuesView {
|
pub struct IssuesView {
|
||||||
workspace: WeakEntity<AppRoot>,
|
workspace: WeakEntity<AppRoot>,
|
||||||
store: Entity<RepoStore>,
|
store: Entity<RepoStore>,
|
||||||
new_issue: Option<Entity<new_issue::NewIssueDialog>>,
|
|
||||||
filter: IssueFilter,
|
filter: IssueFilter,
|
||||||
visible_issues: Vec<usize>,
|
visible_issues: Vec<usize>,
|
||||||
counts: StatusCounts,
|
counts: StatusCounts,
|
||||||
@@ -50,18 +49,20 @@ impl IssuesView {
|
|||||||
store: Entity<RepoStore>,
|
store: Entity<RepoStore>,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let weak = cx.entity().downgrade();
|
||||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
let subscription = cx.observe(&store, |this, _store, cx| {
|
||||||
this.rebuild(cx);
|
this.rebuild(cx);
|
||||||
});
|
});
|
||||||
let weak = cx.entity().downgrade();
|
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
log_dropped(weak.update(cx, |this, cx| this.rebuild(cx)));
|
log_dropped(weak.update(cx, |this, cx| {
|
||||||
|
this.rebuild(cx);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
workspace,
|
workspace,
|
||||||
store: store.clone(),
|
store: store.clone(),
|
||||||
new_issue: None,
|
|
||||||
filter: IssueFilter::Open,
|
filter: IssueFilter::Open,
|
||||||
visible_issues: Vec::new(),
|
visible_issues: Vec::new(),
|
||||||
counts: StatusCounts::default(),
|
counts: StatusCounts::default(),
|
||||||
@@ -73,8 +74,8 @@ impl IssuesView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn open_new_issue(&mut self, cx: &mut Context<Self>) {
|
fn open_new_issue(&mut self, cx: &mut Context<Self>) {
|
||||||
self.new_issue = Some(new_issue::NewIssueDialog::new(self.store.clone(), cx));
|
let dialog = NewIssueDialog::new(self.store.clone(), cx);
|
||||||
cx.notify();
|
cx.open_dialog(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Total number of issues across all statuses, for the sidebar label.
|
/// Total number of issues across all statuses, for the sidebar label.
|
||||||
@@ -230,7 +231,6 @@ impl Render for IssuesView {
|
|||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.size_full()
|
.size_full()
|
||||||
.when_some(self.new_issue.clone(), |el, view| el.child(view))
|
|
||||||
.child(
|
.child(
|
||||||
EventList::new("issues")
|
EventList::new("issues")
|
||||||
.toolbar(self.render_header(cx))
|
.toolbar(self.render_header(cx))
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ use std::sync::Arc;
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
ParentElement as _, Render, SharedString, StyleRefinement, Styled as _, Subscription,
|
||||||
WeakEntity, Window, div,
|
UniformListScrollHandle, WeakEntity, Window, div,
|
||||||
};
|
};
|
||||||
use metadata::ProfileDirectory;
|
use metadata::ProfileDirectory;
|
||||||
use nostr::prelude::{EventId, Kind, Url};
|
use nostr::prelude::{EventId, Kind, Url};
|
||||||
use signed_core::{GitEvent, PullRequest, RepoAddr};
|
use signed_core::{GitEvent, PullRequest, RepoAddr};
|
||||||
use signed_git::{FileCommit, PatchParser};
|
use signed_git::{FileCommit, PatchParser};
|
||||||
use signed_state::{Backend, Mirrors, RepoStore};
|
use signed_state::{Backend, BackendEvent, Mirrors, RepoStore};
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::Button;
|
use ui::button::Button;
|
||||||
use ui::clipboard::ClipboardButton;
|
use ui::clipboard::ClipboardButton;
|
||||||
@@ -20,15 +20,16 @@ use ui::empty_state::EmptyState;
|
|||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
use ui::input::InputState;
|
use ui::input::InputState;
|
||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::Panel;
|
||||||
|
use ui::layout::root::RootContext as _;
|
||||||
use ui::scroll_area::ScrollArea;
|
use ui::scroll_area::ScrollArea;
|
||||||
use ui::spinner::Spinner;
|
use ui::spinner::Spinner;
|
||||||
use ui::tabs::{Tab, Tabs};
|
use ui::tabs::{Tab, Tabs};
|
||||||
use ui::theme::ActiveTheme as _;
|
use ui::theme::ActiveTheme as _;
|
||||||
use utils::relative_time;
|
use utils::relative_time;
|
||||||
|
|
||||||
use super::dialogs;
|
|
||||||
use crate::app::AppRoot;
|
use crate::app::AppRoot;
|
||||||
use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
|
use crate::issues::helpers::{comment_form, comments_section, sidebar_section};
|
||||||
|
use crate::pull_requests::dialogs::update::UpdatePrDialog;
|
||||||
use crate::repo::commit_diff::{CommitDiffView, DiffPane};
|
use crate::repo::commit_diff::{CommitDiffView, DiffPane};
|
||||||
use crate::shared::event_list::commit_list;
|
use crate::shared::event_list::commit_list;
|
||||||
use crate::shared::log_dropped;
|
use crate::shared::log_dropped;
|
||||||
@@ -52,7 +53,6 @@ pub struct PullRequestDetailView {
|
|||||||
workspace: WeakEntity<AppRoot>,
|
workspace: WeakEntity<AppRoot>,
|
||||||
store: Entity<RepoStore>,
|
store: Entity<RepoStore>,
|
||||||
pr_id: EventId,
|
pr_id: EventId,
|
||||||
update_dialog: Option<Entity<dialogs::update::UpdatePrDialog>>,
|
|
||||||
comment_input: Entity<InputState>,
|
comment_input: Entity<InputState>,
|
||||||
worktree: Option<PathBuf>,
|
worktree: Option<PathBuf>,
|
||||||
description: SharedString,
|
description: SharedString,
|
||||||
@@ -67,7 +67,7 @@ pub struct PullRequestDetailView {
|
|||||||
commit_scroll_handle: UniformListScrollHandle,
|
commit_scroll_handle: UniformListScrollHandle,
|
||||||
tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
|
tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
|
||||||
directory: Entity<ProfileDirectory>,
|
directory: Entity<ProfileDirectory>,
|
||||||
_subscription: Subscription,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PullRequestDetailView {
|
impl PullRequestDetailView {
|
||||||
@@ -78,23 +78,35 @@ impl PullRequestDetailView {
|
|||||||
_window: &mut Window,
|
_window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let pane = cx.new(DiffPane::new);
|
|
||||||
let comment_input = InputState::builder().multiline().build(cx);
|
let comment_input = InputState::builder().multiline().build(cx);
|
||||||
|
let directory = ProfileDirectory::new(cx);
|
||||||
|
|
||||||
|
let pane = cx.new(DiffPane::new);
|
||||||
let weak = cx.entity().downgrade();
|
let weak = cx.entity().downgrade();
|
||||||
|
|
||||||
let subscription = cx.observe(&store, |this, _store, cx| {
|
let backend = Backend::global(cx);
|
||||||
|
let mut subscriptions = vec![];
|
||||||
|
|
||||||
|
subscriptions.push(cx.observe(&store, |this, _store, cx| {
|
||||||
this.sync(cx);
|
this.sync(cx);
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
subscriptions.push(cx.subscribe(&backend, |_, _, event, cx| {
|
||||||
|
if matches!(event, BackendEvent::SignerChanged) {
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
log_dropped(weak.update(cx, |this, cx| this.sync(cx)));
|
log_dropped(weak.update(cx, |this, cx| {
|
||||||
|
this.sync(cx);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
workspace,
|
workspace,
|
||||||
store,
|
store,
|
||||||
pr_id,
|
pr_id,
|
||||||
update_dialog: None,
|
|
||||||
comment_input,
|
comment_input,
|
||||||
worktree: None,
|
worktree: None,
|
||||||
description: SharedString::default(),
|
description: SharedString::default(),
|
||||||
@@ -108,8 +120,8 @@ impl PullRequestDetailView {
|
|||||||
pane,
|
pane,
|
||||||
commit_scroll_handle: UniformListScrollHandle::new(),
|
commit_scroll_handle: UniformListScrollHandle::new(),
|
||||||
tasks: Vec::new(),
|
tasks: Vec::new(),
|
||||||
directory: ProfileDirectory::new(cx),
|
directory,
|
||||||
_subscription: subscription,
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,10 +457,15 @@ impl PullRequestDetailView {
|
|||||||
if self.loading {
|
if self.loading {
|
||||||
return Spinner::centered("pr-loading");
|
return Spinner::centered("pr-loading");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(error) = self.error.clone() {
|
if let Some(error) = self.error.clone() {
|
||||||
return EmptyState::centered(error);
|
return EmptyState::centered(error);
|
||||||
}
|
}
|
||||||
self.pane.clone().into_any_element()
|
|
||||||
|
self.pane
|
||||||
|
.clone()
|
||||||
|
.cached(StyleRefinement::default().size_full().min_h_0())
|
||||||
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_commits(&self, cx: &mut Context<Self>) -> AnyElement {
|
fn render_commits(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||||
@@ -545,14 +562,11 @@ impl PullRequestDetailView {
|
|||||||
pr.id == this.pr_id && pr.kind == Kind::GitPullRequest
|
pr.id == this.pr_id && pr.kind == Kind::GitPullRequest
|
||||||
})
|
})
|
||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
if let Some(root) = root {
|
if let Some(root) = root {
|
||||||
this.update_dialog =
|
let dialog =
|
||||||
Some(dialogs::update::UpdatePrDialog::new(
|
UpdatePrDialog::new(this.store.clone(), root, cx);
|
||||||
this.store.clone(),
|
cx.open_dialog(dialog);
|
||||||
root,
|
|
||||||
cx,
|
|
||||||
));
|
|
||||||
cx.notify();
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
@@ -597,7 +611,6 @@ impl Render for PullRequestDetailView {
|
|||||||
.size_full()
|
.size_full()
|
||||||
.min_h_0()
|
.min_h_0()
|
||||||
.child(self.render_header(cx))
|
.child(self.render_header(cx))
|
||||||
.when_some(self.update_dialog.clone(), |el, view| el.child(view))
|
|
||||||
.child(self.render_tabs(cx))
|
.child(self.render_tabs(cx))
|
||||||
.map(|this| match self.active_tab {
|
.map(|this| match self.active_tab {
|
||||||
0 => this.child(self.render_discussion(cx)),
|
0 => this.child(self.render_discussion(cx)),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{SharedString, WeakEntity};
|
use gpui::{SharedString, WeakEntity};
|
||||||
use nostr::prelude::PublicKey;
|
use nostr::prelude::PublicKey;
|
||||||
@@ -66,27 +67,29 @@ pub fn truncate_label(label: &str) -> SharedString {
|
|||||||
|
|
||||||
pub fn source_menu_items(
|
pub fn source_menu_items(
|
||||||
view: WeakEntity<NewPullRequestView>,
|
view: WeakEntity<NewPullRequestView>,
|
||||||
associated: Vec<PathBuf>,
|
associated: Arc<Vec<PathBuf>>,
|
||||||
active_path: Option<PathBuf>,
|
active_path: Option<PathBuf>,
|
||||||
candidates: Vec<Announcement>,
|
candidates: Arc<Vec<Announcement>>,
|
||||||
user: Option<PublicKey>,
|
user: Option<PublicKey>,
|
||||||
active_fork: Option<RepoAddr>,
|
active_fork: Option<RepoAddr>,
|
||||||
) -> Vec<MenuItem> {
|
) -> Vec<MenuItem> {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
for path in associated {
|
for (index, path) in associated.iter().enumerate() {
|
||||||
let label = path
|
let label = path
|
||||||
.file_name()
|
.file_name()
|
||||||
.map(|name| name.to_string_lossy().into_owned())
|
.map(|name| name.to_string_lossy().into_owned())
|
||||||
.unwrap_or_else(|| path.display().to_string());
|
.unwrap_or_else(|| path.display().to_string());
|
||||||
|
|
||||||
let target = view.clone();
|
let target = view.clone();
|
||||||
let path_for_action = path.clone();
|
let associated = Arc::clone(&associated);
|
||||||
|
|
||||||
items.push(
|
items.push(
|
||||||
MenuItem::new(truncate_label(&label))
|
MenuItem::new(truncate_label(&label))
|
||||||
.checked(active_path.as_ref() == Some(&path))
|
.checked(active_path.as_ref() == Some(path))
|
||||||
.handler(move |window, cx| {
|
.handler(move |window, cx| {
|
||||||
let path = path_for_action.clone();
|
let Some(path) = associated.get(index).cloned() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
if let Err(error) =
|
if let Err(error) =
|
||||||
target.update(cx, |this, cx| this.apply_folder_path(path, window, cx))
|
target.update(cx, |this, cx| this.apply_folder_path(path, window, cx))
|
||||||
{
|
{
|
||||||
@@ -110,23 +113,25 @@ pub fn source_menu_items(
|
|||||||
if candidates.is_empty() {
|
if candidates.is_empty() {
|
||||||
items.push(MenuItem::new("No announced forks of this repository").disabled(true));
|
items.push(MenuItem::new("No announced forks of this repository").disabled(true));
|
||||||
} else {
|
} else {
|
||||||
for candidate in candidates {
|
for (index, candidate) in candidates.iter().enumerate() {
|
||||||
let subtitle = if Some(candidate.owner) == user {
|
let subtitle = if Some(candidate.owner) == user {
|
||||||
SharedString::from("Your fork")
|
SharedString::from("Your fork")
|
||||||
} else {
|
} else {
|
||||||
SharedString::from(format!("by {}", shorten_owner(&candidate.owner)))
|
SharedString::from(format!("by {}", shorten_owner(&candidate.owner)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let title = format!("{} — {}", announcement_display_name(&candidate), subtitle);
|
let title = format!("{} — {}", announcement_display_name(candidate), subtitle);
|
||||||
let target = view.clone();
|
let target = view.clone();
|
||||||
|
let candidates = Arc::clone(&candidates);
|
||||||
let checked = active_fork == Some(candidate.addr());
|
let checked = active_fork == Some(candidate.addr());
|
||||||
let announcement = candidate;
|
|
||||||
|
|
||||||
items.push(
|
items.push(
|
||||||
MenuItem::new(truncate_label(&title))
|
MenuItem::new(truncate_label(&title))
|
||||||
.checked(checked)
|
.checked(checked)
|
||||||
.handler(move |window, cx| {
|
.handler(move |window, cx| {
|
||||||
let announcement = announcement.clone();
|
let Some(announcement) = candidates.get(index).cloned() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
if let Err(error) =
|
if let Err(error) =
|
||||||
target.update(cx, |this, cx| this.choose_fork(announcement, window, cx))
|
target.update(cx, |this, cx| this.choose_fork(announcement, window, cx))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ use std::sync::Arc;
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, PathPromptOptions, Render, SharedString, Styled as _,
|
ParentElement as _, PathPromptOptions, Render, SharedString, StyleRefinement, Styled as _,
|
||||||
UniformListScrollHandle, WeakEntity, Window, div, px,
|
Subscription, UniformListScrollHandle, WeakEntity, Window, div, px,
|
||||||
};
|
};
|
||||||
use nostr::prelude::Url;
|
use nostr::prelude::{PublicKey, Url};
|
||||||
use signed_core::Announcement;
|
use signed_core::Announcement;
|
||||||
use signed_git::{GitCache, Repo};
|
use signed_git::{GitCache, Repo};
|
||||||
use signed_state::{Backend, CheckoutsStore, Mirrors, RepoListStore, RepoStore};
|
use signed_state::{Backend, BackendEvent, CheckoutsStore, Mirrors, RepoListStore, RepoStore};
|
||||||
use ui::button::{Button, ButtonVariant};
|
use ui::button::{Button, ButtonVariant};
|
||||||
use ui::combobox::{Combobox, ComboboxState};
|
use ui::combobox::{Combobox, ComboboxState};
|
||||||
use ui::common::{StyledExt as _, h_flex, v_flex};
|
use ui::common::{StyledExt as _, h_flex, v_flex};
|
||||||
@@ -56,6 +56,11 @@ pub struct NewPullRequestView {
|
|||||||
scroll_handle: UniformListScrollHandle,
|
scroll_handle: UniformListScrollHandle,
|
||||||
pub(super) tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
|
pub(super) tasks: Vec<gpui::Task<Result<(), anyhow::Error>>>,
|
||||||
source_open: bool,
|
source_open: bool,
|
||||||
|
/// The checkouts, forks, and user the source menu lists.
|
||||||
|
checkouts: Arc<Vec<PathBuf>>,
|
||||||
|
forks: Arc<Vec<Announcement>>,
|
||||||
|
user: Option<PublicKey>,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewPullRequestView {
|
impl NewPullRequestView {
|
||||||
@@ -66,12 +71,16 @@ impl NewPullRequestView {
|
|||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let pane = cx.new(DiffPane::new);
|
let checkouts = CheckoutsStore::global(cx);
|
||||||
|
let repositories = RepoListStore::global(cx);
|
||||||
|
let backend = Backend::global(cx);
|
||||||
|
|
||||||
let weak = cx.entity().downgrade();
|
|
||||||
let subject = InputState::new(cx);
|
let subject = InputState::new(cx);
|
||||||
let description = InputState::builder().multiline().build(cx);
|
let description = InputState::builder().multiline().build(cx);
|
||||||
|
|
||||||
|
let pane = cx.new(DiffPane::new);
|
||||||
|
let weak = cx.entity().downgrade();
|
||||||
|
|
||||||
let base_select = cx.new(|cx| {
|
let base_select = cx.new(|cx| {
|
||||||
ComboboxState::new(
|
ComboboxState::new(
|
||||||
Combobox::new("pr-base", "Base", Vec::new()).on_change({
|
Combobox::new("pr-base", "Base", Vec::new()).on_change({
|
||||||
@@ -114,8 +123,27 @@ impl NewPullRequestView {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.defer(cx, move |window, cx| {
|
let mut subscriptions = vec![];
|
||||||
log_dropped(weak.update(cx, |this, cx| {
|
|
||||||
|
subscriptions.push(cx.observe(&checkouts, |this, _, cx| {
|
||||||
|
this.refresh_sources(cx);
|
||||||
|
}));
|
||||||
|
|
||||||
|
subscriptions.push(cx.observe(&repositories, |this, _, cx| {
|
||||||
|
this.refresh_sources(cx);
|
||||||
|
}));
|
||||||
|
|
||||||
|
subscriptions.push(cx.observe(&store, |this, _, cx| {
|
||||||
|
this.refresh_sources(cx);
|
||||||
|
}));
|
||||||
|
|
||||||
|
subscriptions.push(cx.subscribe(&backend, |this, _, event, cx| {
|
||||||
|
if matches!(event, BackendEvent::SignerChanged) {
|
||||||
|
this.refresh_sources(cx);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
cx.defer_in(window, move |this, window, cx| {
|
||||||
let Some(addr) = this.store.read(cx).addr().cloned() else {
|
let Some(addr) = this.store.read(cx).addr().cloned() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -130,7 +158,7 @@ impl NewPullRequestView {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.apply_folder_path(path, window, cx);
|
this.apply_folder_path(path, window, cx);
|
||||||
}));
|
this.refresh_sources(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@@ -158,6 +186,10 @@ impl NewPullRequestView {
|
|||||||
scroll_handle: UniformListScrollHandle::new(),
|
scroll_handle: UniformListScrollHandle::new(),
|
||||||
tasks: Vec::new(),
|
tasks: Vec::new(),
|
||||||
source_open: false,
|
source_open: false,
|
||||||
|
checkouts: Arc::default(),
|
||||||
|
forks: Arc::default(),
|
||||||
|
user: None,
|
||||||
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,19 +290,17 @@ impl NewPullRequestView {
|
|||||||
let weak = cx.entity().downgrade();
|
let weak = cx.entity().downgrade();
|
||||||
let weak_menu = cx.entity().downgrade();
|
let weak_menu = cx.entity().downgrade();
|
||||||
let source_view = cx.entity().downgrade();
|
let source_view = cx.entity().downgrade();
|
||||||
let associated = self
|
let associated = Arc::clone(&self.checkouts);
|
||||||
.store
|
|
||||||
.read(cx)
|
|
||||||
.addr()
|
|
||||||
.map(|addr| CheckoutsStore::global(cx).read(cx).associations_of(addr))
|
|
||||||
.unwrap_or_default();
|
|
||||||
let active_path = (self.fork.is_none())
|
let active_path = (self.fork.is_none())
|
||||||
.then(|| self.repo_path.clone())
|
.then(|| self.repo_path.clone())
|
||||||
.flatten();
|
.flatten();
|
||||||
let candidates = self.fork_candidates(cx);
|
|
||||||
|
let candidates = Arc::clone(&self.forks);
|
||||||
let user = signed_state::Backend::global(cx).read(cx).current_user();
|
let user = signed_state::Backend::global(cx).read(cx).current_user();
|
||||||
let active_fork = self.fork.as_ref().map(|fork| fork.announcement.addr());
|
let active_fork = self.fork.as_ref().map(|fork| fork.announcement.addr());
|
||||||
let can_submit = self.submit_enabled(cx);
|
let can_submit = self.submit_enabled(cx);
|
||||||
|
|
||||||
let source_label = match &self.fork {
|
let source_label = match &self.fork {
|
||||||
Some(fork) => truncate_label(&announcement_display_name(&fork.announcement)),
|
Some(fork) => truncate_label(&announcement_display_name(&fork.announcement)),
|
||||||
None => self.repo_path.as_ref().map_or_else(
|
None => self.repo_path.as_ref().map_or_else(
|
||||||
@@ -379,14 +409,21 @@ impl NewPullRequestView {
|
|||||||
if self.loading {
|
if self.loading {
|
||||||
return Spinner::centered("new-pr-loading");
|
return Spinner::centered("new-pr-loading");
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.has_source() {
|
if !self.has_source() {
|
||||||
return EmptyState::centered("Choose a local checkout or an announced fork to compare");
|
return EmptyState::centered("Choose a local checkout or an announced fork to compare");
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.commits.is_none() && self.error.is_some() {
|
if self.commits.is_none() && self.error.is_some() {
|
||||||
return EmptyState::centered("Nothing to compare");
|
return EmptyState::centered("Nothing to compare");
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.active_tab {
|
match self.active_tab {
|
||||||
0 => self.pane.clone().into_any_element(),
|
0 => self
|
||||||
|
.pane
|
||||||
|
.clone()
|
||||||
|
.cached(StyleRefinement::default().size_full().min_h_0())
|
||||||
|
.into_any_element(),
|
||||||
_ => self.render_commits(cx),
|
_ => self.render_commits(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -575,22 +612,51 @@ impl NewPullRequestView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn fork_candidates(&self, cx: &App) -> Vec<Announcement> {
|
/// Rebuilds the source menu's checkouts, forks, and user when their inputs changed.
|
||||||
let Some(addr) = self.store.read(cx).addr().cloned() else {
|
fn refresh_sources(&mut self, cx: &mut Context<Self>) {
|
||||||
return Vec::new();
|
let (addr, euc) = {
|
||||||
};
|
let store = self.store.read(cx);
|
||||||
let euc = self
|
(
|
||||||
.store
|
store.addr().cloned(),
|
||||||
.read(cx)
|
store
|
||||||
.announcement
|
.announcement
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|a| a.euc.clone());
|
.and_then(|announcement| announcement.euc.clone()),
|
||||||
let user = Backend::global(cx).read(cx).current_user();
|
)
|
||||||
let announcements = RepoListStore::global(cx).read(cx).announcements.clone();
|
};
|
||||||
Announcement::forks_in(&announcements, &addr, euc.as_deref(), user)
|
|
||||||
|
let checkouts = CheckoutsStore::global(cx);
|
||||||
|
let repositories = RepoListStore::global(cx);
|
||||||
|
let backend = Backend::global(cx);
|
||||||
|
let user = backend.read(cx).current_user();
|
||||||
|
let checkouts = addr
|
||||||
|
.as_ref()
|
||||||
|
.map_or_else(Vec::new, |addr| checkouts.read(cx).associations_of(addr));
|
||||||
|
|
||||||
|
let forks: Vec<Announcement> = addr.as_ref().map_or_else(Vec::new, |addr| {
|
||||||
|
Announcement::forks_in(
|
||||||
|
&repositories.read(cx).announcements,
|
||||||
|
addr,
|
||||||
|
euc.as_deref(),
|
||||||
|
user,
|
||||||
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
|
});
|
||||||
|
|
||||||
|
if self.user == user
|
||||||
|
&& self.checkouts.as_slice() == checkouts.as_slice()
|
||||||
|
&& self.forks.as_slice() == forks.as_slice()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.user = user;
|
||||||
|
self.checkouts = Arc::new(checkouts);
|
||||||
|
self.forks = Arc::new(forks);
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn choose_fork(
|
pub(crate) fn choose_fork(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@@ -57,15 +58,15 @@ enum PaneRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct DiffPane {
|
pub struct DiffPane {
|
||||||
diff: Option<CommitDiff>,
|
diff: Option<Arc<CommitDiff>>,
|
||||||
seeds: Vec<TreeItemSeed>,
|
seeds: Vec<TreeItemSeed>,
|
||||||
expanded: HashSet<String>,
|
expanded: HashSet<String>,
|
||||||
rows: Vec<TreeItem>,
|
rows: Arc<Vec<TreeItem>>,
|
||||||
selected_index: Option<usize>,
|
selected_index: Option<usize>,
|
||||||
tree_visible: bool,
|
tree_visible: bool,
|
||||||
split: Entity<ResizableState>,
|
split: Entity<ResizableState>,
|
||||||
expanded_files: HashSet<String>,
|
expanded_files: HashSet<String>,
|
||||||
pane_rows: Vec<PaneRow>,
|
pane_rows: Arc<Vec<PaneRow>>,
|
||||||
list: ListState,
|
list: ListState,
|
||||||
wrap: bool,
|
wrap: bool,
|
||||||
downloadable: bool,
|
downloadable: bool,
|
||||||
@@ -74,18 +75,20 @@ pub struct DiffPane {
|
|||||||
impl DiffPane {
|
impl DiffPane {
|
||||||
pub fn new(cx: &mut Context<Self>) -> Self {
|
pub fn new(cx: &mut Context<Self>) -> Self {
|
||||||
let split = ResizableState::new(cx);
|
let split = ResizableState::new(cx);
|
||||||
split.update(cx, |split, cx| split.set_sizes([px(260.)], cx));
|
split.update(cx, |split, cx| {
|
||||||
|
split.set_sizes([px(260.)], cx);
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
diff: None,
|
diff: None,
|
||||||
seeds: Vec::new(),
|
seeds: Vec::new(),
|
||||||
expanded: HashSet::new(),
|
expanded: HashSet::new(),
|
||||||
rows: Vec::new(),
|
rows: Arc::default(),
|
||||||
selected_index: None,
|
selected_index: None,
|
||||||
tree_visible: false,
|
tree_visible: false,
|
||||||
split,
|
split,
|
||||||
expanded_files: HashSet::new(),
|
expanded_files: HashSet::new(),
|
||||||
pane_rows: Vec::new(),
|
pane_rows: Arc::default(),
|
||||||
list: ListState::new(0, ListAlignment::Top, px(320.)),
|
list: ListState::new(0, ListAlignment::Top, px(320.)),
|
||||||
wrap: false,
|
wrap: false,
|
||||||
downloadable: false,
|
downloadable: false,
|
||||||
@@ -93,7 +96,7 @@ impl DiffPane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn diff(&self) -> Option<&CommitDiff> {
|
pub fn diff(&self) -> Option<&CommitDiff> {
|
||||||
self.diff.as_ref()
|
self.diff.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_diff(&mut self, diff: CommitDiff, cx: &mut Context<Self>) {
|
pub fn set_diff(&mut self, diff: CommitDiff, cx: &mut Context<Self>) {
|
||||||
@@ -106,9 +109,9 @@ impl DiffPane {
|
|||||||
|
|
||||||
self.seeds = TreeItemSeed::from_paths(&paths);
|
self.seeds = TreeItemSeed::from_paths(&paths);
|
||||||
self.expanded = TreeItemSeed::collect_expanded(&self.seeds);
|
self.expanded = TreeItemSeed::collect_expanded(&self.seeds);
|
||||||
self.rows = TreeItemSeed::flatten_all(&self.seeds, &self.expanded);
|
self.rows = Arc::new(TreeItemSeed::flatten_all(&self.seeds, &self.expanded));
|
||||||
self.selected_index = None;
|
self.selected_index = None;
|
||||||
self.diff = Some(diff);
|
self.diff = Some(Arc::new(diff));
|
||||||
|
|
||||||
self.expanded_files.clear();
|
self.expanded_files.clear();
|
||||||
self.rebuild_rows();
|
self.rebuild_rows();
|
||||||
@@ -120,10 +123,10 @@ impl DiffPane {
|
|||||||
self.diff = None;
|
self.diff = None;
|
||||||
self.seeds.clear();
|
self.seeds.clear();
|
||||||
self.expanded.clear();
|
self.expanded.clear();
|
||||||
self.rows.clear();
|
self.rows = Arc::default();
|
||||||
self.selected_index = None;
|
self.selected_index = None;
|
||||||
self.expanded_files.clear();
|
self.expanded_files.clear();
|
||||||
self.pane_rows.clear();
|
self.pane_rows = Arc::default();
|
||||||
self.list = ListState::new(0, ListAlignment::Top, px(320.));
|
self.list = ListState::new(0, ListAlignment::Top, px(320.));
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
@@ -197,7 +200,7 @@ impl DiffPane {
|
|||||||
|
|
||||||
fn rebuild_rows(&mut self) {
|
fn rebuild_rows(&mut self) {
|
||||||
let Some(diff) = self.diff.as_ref() else {
|
let Some(diff) = self.diff.as_ref() else {
|
||||||
self.pane_rows.clear();
|
self.pane_rows = Arc::default();
|
||||||
self.list.reset(0);
|
self.list.reset(0);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -245,7 +248,7 @@ impl DiffPane {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.pane_rows = pane_rows;
|
self.pane_rows = Arc::new(pane_rows);
|
||||||
self.list.reset(self.pane_rows.len());
|
self.list.reset(self.pane_rows.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,15 +256,17 @@ impl DiffPane {
|
|||||||
if !self.expanded.remove(id) {
|
if !self.expanded.remove(id) {
|
||||||
self.expanded.insert(id.to_owned());
|
self.expanded.insert(id.to_owned());
|
||||||
}
|
}
|
||||||
self.rows = TreeItemSeed::flatten_all(&self.seeds, &self.expanded);
|
|
||||||
|
self.rows = Arc::new(TreeItemSeed::flatten_all(&self.seeds, &self.expanded));
|
||||||
self.selected_index = self
|
self.selected_index = self
|
||||||
.selected_index
|
.selected_index
|
||||||
.and_then(|index| self.rows.get(index).map(|_| index));
|
.and_then(|index| self.rows.get(index).map(|_| index));
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_tree_column(&self, cx: &mut Context<Self>) -> AnyElement {
|
fn render_tree_column(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||||
let rows = self.rows.clone();
|
let rows = Arc::clone(&self.rows);
|
||||||
let selected = self.selected_index;
|
let selected = self.selected_index;
|
||||||
let view = cx.entity().downgrade();
|
let view = cx.entity().downgrade();
|
||||||
let change_view = view.clone();
|
let change_view = view.clone();
|
||||||
@@ -273,7 +278,7 @@ impl DiffPane {
|
|||||||
.child(
|
.child(
|
||||||
Tree::new("commit-diff-tree")
|
Tree::new("commit-diff-tree")
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.items(move |_, _| rows.clone())
|
.items(move |_, _| Arc::clone(&rows))
|
||||||
.on_change(move |index, window, cx| {
|
.on_change(move |index, window, cx| {
|
||||||
if let Some(index) = index
|
if let Some(index) = index
|
||||||
&& let Err(error) = change_view.update(cx, |this, cx| {
|
&& let Err(error) = change_view.update(cx, |this, cx| {
|
||||||
@@ -419,8 +424,8 @@ impl DiffPane {
|
|||||||
return EmptyState::centered("No changes");
|
return EmptyState::centered("No changes");
|
||||||
};
|
};
|
||||||
|
|
||||||
let files = diff.files.clone();
|
let diff = Arc::clone(diff);
|
||||||
let pane_rows = self.pane_rows.clone();
|
let pane_rows = Arc::clone(&self.pane_rows);
|
||||||
let wrap = self.wrap;
|
let wrap = self.wrap;
|
||||||
let view = cx.entity().downgrade();
|
let view = cx.entity().downgrade();
|
||||||
|
|
||||||
@@ -433,7 +438,7 @@ impl DiffPane {
|
|||||||
.child(
|
.child(
|
||||||
list(self.list.clone(), move |ix, _, cx| {
|
list(self.list.clone(), move |ix, _, cx| {
|
||||||
match pane_rows.get(ix) {
|
match pane_rows.get(ix) {
|
||||||
Some(row) => render_pane_row(row, &files, &view, wrap, cx),
|
Some(row) => render_pane_row(row, &diff.files, &view, wrap, cx),
|
||||||
None => div().into_any_element(),
|
None => div().into_any_element(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||||
SharedString, Styled as _, Window, div, px,
|
SharedString, Styled as _, Window, div, px,
|
||||||
@@ -14,13 +16,13 @@ use utils::middle_truncate;
|
|||||||
|
|
||||||
pub struct AboutDialog {
|
pub struct AboutDialog {
|
||||||
handle: DialogHandle,
|
handle: DialogHandle,
|
||||||
announcement: Announcement,
|
announcement: Arc<Announcement>,
|
||||||
directory: Entity<ProfileDirectory>,
|
directory: Entity<ProfileDirectory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AboutDialog {
|
impl AboutDialog {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
announcement: Announcement,
|
announcement: Arc<Announcement>,
|
||||||
directory: Entity<ProfileDirectory>,
|
directory: Entity<ProfileDirectory>,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> Entity<Self> {
|
) -> Entity<Self> {
|
||||||
|
|||||||
@@ -108,8 +108,7 @@ pub fn grasp_servers_field(
|
|||||||
v_flex().gap_1().children(
|
v_flex().gap_1().children(
|
||||||
servers
|
servers
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.map(|relay| render_server_row(relay, state.clone(), cx)),
|
||||||
.map(|(ix, relay)| render_server_row(ix, relay, state.clone(), cx)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -144,12 +143,7 @@ pub fn grasp_servers_field(
|
|||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_server_row(
|
fn render_server_row(relay: &RelayUrl, state: Entity<GraspServersState>, cx: &App) -> AnyElement {
|
||||||
ix: usize,
|
|
||||||
relay: &RelayUrl,
|
|
||||||
state: Entity<GraspServersState>,
|
|
||||||
cx: &App,
|
|
||||||
) -> AnyElement {
|
|
||||||
let relay = relay.clone();
|
let relay = relay.clone();
|
||||||
h_flex()
|
h_flex()
|
||||||
.w_full()
|
.w_full()
|
||||||
@@ -167,19 +161,14 @@ fn render_server_row(
|
|||||||
.child(server_host(&relay)),
|
.child(server_host(&relay)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
Button::new(SharedString::from(format!("remove-relay:{ix}")))
|
Button::new(SharedString::from(format!("remove-relay:{relay}")))
|
||||||
.icon(Icon::named(IconRole::Close))
|
.icon(Icon::named(IconRole::Close))
|
||||||
.variant(ButtonVariant::Ghost)
|
.variant(ButtonVariant::Ghost)
|
||||||
.tooltip(Tooltip::text("Remove"))
|
.tooltip(Tooltip::text("Remove"))
|
||||||
.on_click(move |_, _, cx| {
|
.on_click(move |_, _, cx| {
|
||||||
// A row's index can desync after a prior removal; match by value.
|
|
||||||
state.update(cx, |state, cx| {
|
state.update(cx, |state, cx| {
|
||||||
if let Some(at) =
|
state.grasp_servers.retain(|known| known != &relay);
|
||||||
state.grasp_servers.iter().position(|known| known == &relay)
|
|
||||||
{
|
|
||||||
state.grasp_servers.remove(at);
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,3 +3,118 @@ pub mod create;
|
|||||||
pub mod grasp_servers;
|
pub mod grasp_servers;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod reset;
|
pub mod reset;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||||
|
SharedString, Styled as _, WeakEntity, Window, div,
|
||||||
|
};
|
||||||
|
use ui::button::{Button, ButtonVariant};
|
||||||
|
use ui::dialog::{Dialog, DialogHandle};
|
||||||
|
use ui::theme::ActiveTheme as _;
|
||||||
|
|
||||||
|
use crate::repo::RepoDetailView;
|
||||||
|
use crate::shared::log_dropped;
|
||||||
|
|
||||||
|
/// A sync failed; explains why.
|
||||||
|
pub struct SyncErrorDialog {
|
||||||
|
handle: DialogHandle,
|
||||||
|
message: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyncErrorDialog {
|
||||||
|
pub fn new(message: SharedString, cx: &mut App) -> Entity<Self> {
|
||||||
|
cx.new(|_| Self {
|
||||||
|
handle: DialogHandle::new(true),
|
||||||
|
message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for SyncErrorDialog {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let close = self.handle.clone();
|
||||||
|
let message = self.message.clone();
|
||||||
|
|
||||||
|
Dialog::new("sync-error-dialog")
|
||||||
|
.handle(self.handle.clone())
|
||||||
|
.alert(true)
|
||||||
|
.title("Sync failed")
|
||||||
|
.content(move |_, cx| {
|
||||||
|
div()
|
||||||
|
.text_base()
|
||||||
|
.text_color(cx.theme().colors.muted_foreground)
|
||||||
|
.child(message.clone())
|
||||||
|
.into_any_element()
|
||||||
|
})
|
||||||
|
.actions(move |_, _| {
|
||||||
|
let close = close.clone();
|
||||||
|
vec![
|
||||||
|
Button::new("close-sync-error")
|
||||||
|
.label("Close")
|
||||||
|
.variant(ButtonVariant::Secondary)
|
||||||
|
.on_click(move |_, _, cx| close.close(cx))
|
||||||
|
.into_any_element(),
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asks before the repository's events are deleted from Nostr.
|
||||||
|
pub struct DeleteRepositoryDialog {
|
||||||
|
handle: DialogHandle,
|
||||||
|
view: WeakEntity<RepoDetailView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeleteRepositoryDialog {
|
||||||
|
pub fn new(view: WeakEntity<RepoDetailView>, cx: &mut App) -> Entity<Self> {
|
||||||
|
cx.new(|_| Self {
|
||||||
|
handle: DialogHandle::new(true),
|
||||||
|
view,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for DeleteRepositoryDialog {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
const WARNING: &str = "This removes the repository's announcement, state, and activity from Nostr. This cannot be undone.";
|
||||||
|
|
||||||
|
let cancel_close = self.handle.clone();
|
||||||
|
let confirm_close = self.handle.clone();
|
||||||
|
let view = self.view.clone();
|
||||||
|
|
||||||
|
Dialog::new("delete-repository-dialog")
|
||||||
|
.handle(self.handle.clone())
|
||||||
|
.alert(true)
|
||||||
|
.title("Delete repository")
|
||||||
|
.content(|_, cx| {
|
||||||
|
div()
|
||||||
|
.text_base()
|
||||||
|
.text_color(cx.theme().colors.muted_foreground)
|
||||||
|
.child(WARNING)
|
||||||
|
.into_any_element()
|
||||||
|
})
|
||||||
|
.actions(move |_, _| {
|
||||||
|
let cancel_close = cancel_close.clone();
|
||||||
|
let confirm_close = confirm_close.clone();
|
||||||
|
let cancel: AnyElement = Button::new("cancel-delete")
|
||||||
|
.label("Cancel")
|
||||||
|
.variant(ButtonVariant::Secondary)
|
||||||
|
.on_click(move |_, _, cx| cancel_close.close(cx))
|
||||||
|
.into_any_element();
|
||||||
|
|
||||||
|
let delete: AnyElement = Button::new("confirm-delete")
|
||||||
|
.label("Delete")
|
||||||
|
.variant(ButtonVariant::Destructive)
|
||||||
|
.on_click({
|
||||||
|
let view = view.clone();
|
||||||
|
move |_, _, cx| {
|
||||||
|
confirm_close.close(cx);
|
||||||
|
log_dropped(view.update(cx, |this, cx| this.delete_repository(cx)));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into_any_element();
|
||||||
|
|
||||||
|
vec![cancel, delete]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use std::collections::{HashMap, HashSet, VecDeque};
|
use std::collections::{HashMap, HashSet, VecDeque};
|
||||||
use std::path::{Component, Path, PathBuf};
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, IntoElement,
|
||||||
ParentElement as _, SharedString, Styled as _, Task, WeakEntity, Window, div, px,
|
ParentElement as _, Render, SharedString, StyleRefinement, Styled as _, Task, WeakEntity,
|
||||||
|
Window, div, px,
|
||||||
};
|
};
|
||||||
use signed_git::{FileCommit, Repo, WorktreeSnapshot};
|
use signed_git::{FileCommit, Repo, WorktreeSnapshot};
|
||||||
use ui::code::CodeViewState;
|
use ui::code::CodeViewState;
|
||||||
@@ -55,7 +57,7 @@ struct CodeView {
|
|||||||
pub struct RepoFilesView {
|
pub struct RepoFilesView {
|
||||||
seeds: Vec<TreeItemSeed>,
|
seeds: Vec<TreeItemSeed>,
|
||||||
expanded: HashSet<String>,
|
expanded: HashSet<String>,
|
||||||
rows: Vec<TreeItem>,
|
rows: Arc<Vec<TreeItem>>,
|
||||||
selected_index: Option<usize>,
|
selected_index: Option<usize>,
|
||||||
worktree: Option<PathBuf>,
|
worktree: Option<PathBuf>,
|
||||||
worktree_paths: Vec<String>,
|
worktree_paths: Vec<String>,
|
||||||
@@ -82,7 +84,7 @@ impl RepoFilesView {
|
|||||||
Self {
|
Self {
|
||||||
seeds: Vec::new(),
|
seeds: Vec::new(),
|
||||||
expanded: HashSet::new(),
|
expanded: HashSet::new(),
|
||||||
rows: Vec::new(),
|
rows: Arc::default(),
|
||||||
selected_index: None,
|
selected_index: None,
|
||||||
worktree: None,
|
worktree: None,
|
||||||
worktree_paths: Vec::new(),
|
worktree_paths: Vec::new(),
|
||||||
@@ -121,7 +123,7 @@ impl RepoFilesView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rebuild_rows(&mut self) {
|
fn rebuild_rows(&mut self) {
|
||||||
self.rows = TreeItemSeed::flatten_all(&self.seeds, &self.expanded);
|
self.rows = Arc::new(TreeItemSeed::flatten_all(&self.seeds, &self.expanded));
|
||||||
self.selected_index = self.selected_file.as_ref().and_then(|path| {
|
self.selected_index = self.selected_file.as_ref().and_then(|path| {
|
||||||
self.rows
|
self.rows
|
||||||
.iter()
|
.iter()
|
||||||
@@ -253,7 +255,7 @@ impl RepoFilesView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_tree(&self, view: WeakEntity<Self>) -> AnyElement {
|
pub fn render_tree(&self, view: WeakEntity<Self>) -> AnyElement {
|
||||||
let rows = self.rows.clone();
|
let rows = Arc::clone(&self.rows);
|
||||||
let selected = self.selected_index;
|
let selected = self.selected_index;
|
||||||
let change_view = view.clone();
|
let change_view = view.clone();
|
||||||
let disclosure_view = view;
|
let disclosure_view = view;
|
||||||
@@ -265,7 +267,7 @@ impl RepoFilesView {
|
|||||||
.child(
|
.child(
|
||||||
Tree::new("repo-tree")
|
Tree::new("repo-tree")
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.items(move |_, _| rows.clone())
|
.items(move |_, _| Arc::clone(&rows))
|
||||||
.on_change({
|
.on_change({
|
||||||
let view = change_view;
|
let view = change_view;
|
||||||
move |index, window, cx| {
|
move |index, window, cx| {
|
||||||
@@ -434,7 +436,11 @@ impl RepoFilesView {
|
|||||||
.p_4()
|
.p_4()
|
||||||
.size_full()
|
.size_full()
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.child(md.state.clone())
|
.child(
|
||||||
|
md.state
|
||||||
|
.clone()
|
||||||
|
.cached(StyleRefinement::default().size_full()),
|
||||||
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,7 +488,11 @@ impl RepoFilesView {
|
|||||||
div()
|
div()
|
||||||
.size_full()
|
.size_full()
|
||||||
.overflow_hidden()
|
.overflow_hidden()
|
||||||
.child(code.state.clone())
|
.child(
|
||||||
|
code.state
|
||||||
|
.clone()
|
||||||
|
.cached(StyleRefinement::default().size_full()),
|
||||||
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,3 +736,9 @@ impl RepoFilesView {
|
|||||||
self.push_task(task);
|
self.push_task(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Render for RepoFilesView {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.render_tree(cx.entity().downgrade())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
|
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
|
||||||
Styled as _, Subscription, SystemNotification, Task, WeakEntity, Window, div, px,
|
StyleRefinement, Styled as _, Subscription, SystemNotification, Task, WeakEntity, Window, div,
|
||||||
|
px,
|
||||||
};
|
};
|
||||||
use metadata::ProfileDirectory;
|
use metadata::ProfileDirectory;
|
||||||
use nostr::prelude::{PublicKey, Url};
|
use nostr::prelude::{PublicKey, Url};
|
||||||
@@ -22,10 +24,10 @@ use ui::badge::Badge;
|
|||||||
use ui::button::{Button, ButtonVariant};
|
use ui::button::{Button, ButtonVariant};
|
||||||
use ui::clipboard::CopyRow;
|
use ui::clipboard::CopyRow;
|
||||||
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
use ui::common::{Sizable as _, StyledExt as _, h_flex, v_flex};
|
||||||
use ui::dialog::Dialog;
|
|
||||||
use ui::dropdown_menu::DropdownMenu;
|
use ui::dropdown_menu::DropdownMenu;
|
||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::Panel;
|
||||||
|
use ui::layout::root::RootContext as _;
|
||||||
use ui::menu::MenuItem;
|
use ui::menu::MenuItem;
|
||||||
use ui::popover::Popover;
|
use ui::popover::Popover;
|
||||||
use ui::sidebar::{Sidebar, SidebarEntry};
|
use ui::sidebar::{Sidebar, SidebarEntry};
|
||||||
@@ -53,6 +55,8 @@ use utils::relative_time_secs;
|
|||||||
use crate::app::AppRoot;
|
use crate::app::AppRoot;
|
||||||
use crate::issues::IssuesView;
|
use crate::issues::IssuesView;
|
||||||
use crate::pull_requests::PullRequestsView;
|
use crate::pull_requests::PullRequestsView;
|
||||||
|
use crate::repo::dialogs::DeleteRepositoryDialog;
|
||||||
|
use crate::repo::dialogs::init::InitRepoDialog;
|
||||||
use crate::repo::helpers::{short_id, sorted_worktree_paths};
|
use crate::repo::helpers::{short_id, sorted_worktree_paths};
|
||||||
use crate::shared::log_dropped;
|
use crate::shared::log_dropped;
|
||||||
|
|
||||||
@@ -72,12 +76,31 @@ pub enum RefKind {
|
|||||||
Tag,
|
Tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The announcement and clone commands the repository header renders.
|
||||||
|
struct AboutModel {
|
||||||
|
announcement: Arc<Announcement>,
|
||||||
|
git_commands: Arc<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AboutModel {
|
||||||
|
/// Rebuilds the model only when the store's announcement changed.
|
||||||
|
fn sync(header: &mut Option<Self>, store: &Entity<RepoStore>, cx: &App) {
|
||||||
|
let announcement = store.read(cx).announcement.as_ref();
|
||||||
|
if header.as_ref().map(|header| header.announcement.as_ref()) == announcement {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*header = announcement.map(|announcement| Self {
|
||||||
|
announcement: Arc::new(announcement.clone()),
|
||||||
|
git_commands: Arc::new(announcement.clone_urls()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RepoDetailView {
|
pub struct RepoDetailView {
|
||||||
pub(super) workspace: WeakEntity<AppRoot>,
|
pub(super) workspace: WeakEntity<AppRoot>,
|
||||||
pub(super) store: Entity<RepoStore>,
|
pub(super) store: Entity<RepoStore>,
|
||||||
about: Option<Entity<dialogs::about::AboutDialog>>,
|
/// The announcement data the header renders, synced from the store.
|
||||||
init: Option<Entity<dialogs::init::InitRepoDialog>>,
|
header: Option<AboutModel>,
|
||||||
reset: Option<Entity<dialogs::reset::ResetRemoteDialog>>,
|
|
||||||
/// A repository opened by address alone starts without an announcement.
|
/// A repository opened by address alone starts without an announcement.
|
||||||
repo_started: bool,
|
repo_started: bool,
|
||||||
/// The file explorer and preview.
|
/// The file explorer and preview.
|
||||||
@@ -103,8 +126,6 @@ pub struct RepoDetailView {
|
|||||||
sync_directory: Entity<SyncStatusDirectory>,
|
sync_directory: Entity<SyncStatusDirectory>,
|
||||||
/// Only a commit sync reports push steps; republish stays silent.
|
/// Only a commit sync reports push steps; republish stays silent.
|
||||||
sync_progress: bool,
|
sync_progress: bool,
|
||||||
/// The push error shown by the modal alert dialog.
|
|
||||||
sync_error: Option<SharedString>,
|
|
||||||
pub(super) repo_menu_open: bool,
|
pub(super) repo_menu_open: bool,
|
||||||
pub(super) clone_open: bool,
|
pub(super) clone_open: bool,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
@@ -199,6 +220,9 @@ impl RepoDetailView {
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let mut header = None;
|
||||||
|
AboutModel::sync(&mut header, &store, cx);
|
||||||
|
|
||||||
let store_for_attach = store.clone();
|
let store_for_attach = store.clone();
|
||||||
window.defer(cx, move |window, cx| {
|
window.defer(cx, move |window, cx| {
|
||||||
log_dropped(weak.update(cx, |this, cx| {
|
log_dropped(weak.update(cx, |this, cx| {
|
||||||
@@ -210,9 +234,7 @@ impl RepoDetailView {
|
|||||||
Self {
|
Self {
|
||||||
workspace,
|
workspace,
|
||||||
store: store.clone(),
|
store: store.clone(),
|
||||||
about: None,
|
header,
|
||||||
init: None,
|
|
||||||
reset: None,
|
|
||||||
repo_started: false,
|
repo_started: false,
|
||||||
files,
|
files,
|
||||||
history,
|
history,
|
||||||
@@ -228,7 +250,6 @@ impl RepoDetailView {
|
|||||||
directory: ProfileDirectory::new(cx),
|
directory: ProfileDirectory::new(cx),
|
||||||
sync_directory,
|
sync_directory,
|
||||||
sync_progress: false,
|
sync_progress: false,
|
||||||
sync_error: None,
|
|
||||||
repo_menu_open: false,
|
repo_menu_open: false,
|
||||||
clone_open: false,
|
clone_open: false,
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
@@ -260,6 +281,7 @@ impl RepoDetailView {
|
|||||||
) {
|
) {
|
||||||
self._subscriptions
|
self._subscriptions
|
||||||
.push(cx.observe_in(store, window, |this, store, window, cx| {
|
.push(cx.observe_in(store, window, |this, store, window, cx| {
|
||||||
|
AboutModel::sync(&mut this.header, &store, cx);
|
||||||
this.track_profiles(cx);
|
this.track_profiles(cx);
|
||||||
this.track_sync_status(cx);
|
this.track_sync_status(cx);
|
||||||
if !this.repo_started && store.read(cx).announcement.is_some() {
|
if !this.repo_started && store.read(cx).announcement.is_some() {
|
||||||
@@ -827,7 +849,6 @@ impl RepoDetailView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.error = None;
|
self.error = None;
|
||||||
self.sync_error = None;
|
|
||||||
self.sync_progress = true;
|
self.sync_progress = true;
|
||||||
|
|
||||||
let tag = store
|
let tag = store
|
||||||
@@ -879,7 +900,8 @@ impl RepoDetailView {
|
|||||||
cx.dismiss_system_notification(tag.as_ref()).detach();
|
cx.dismiss_system_notification(tag.as_ref()).detach();
|
||||||
}
|
}
|
||||||
store.update(cx, |store, _| store.last_error = None);
|
store.update(cx, |store, _| store.last_error = None);
|
||||||
this.sync_error = Some(format!("{error:#}").into());
|
let dialog = dialogs::SyncErrorDialog::new(format!("{error:#}").into(), cx);
|
||||||
|
cx.open_dialog(dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -940,13 +962,9 @@ impl RepoDetailView {
|
|||||||
|
|
||||||
this.update_in(cx, |this, _window, cx| match probe {
|
this.update_in(cx, |this, _window, cx| match probe {
|
||||||
Ok((deleted, unreachable)) => {
|
Ok((deleted, unreachable)) => {
|
||||||
this.reset = Some(dialogs::reset::ResetRemoteDialog::new(
|
let dialog =
|
||||||
store,
|
dialogs::reset::ResetRemoteDialog::new(store, deleted, unreachable, cx);
|
||||||
deleted,
|
cx.open_dialog(dialog);
|
||||||
unreachable,
|
|
||||||
cx,
|
|
||||||
));
|
|
||||||
cx.notify();
|
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
this.error = Some(error.to_string().into());
|
this.error = Some(error.to_string().into());
|
||||||
@@ -960,7 +978,7 @@ impl RepoDetailView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Delete the repository from nostr, announcement, state and activity.
|
/// Delete the repository from nostr, announcement, state and activity.
|
||||||
fn delete_repository(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
fn delete_repository(&mut self, cx: &mut Context<Self>) {
|
||||||
let task = self
|
let task = self
|
||||||
.store
|
.store
|
||||||
.update(cx, |store, cx| store.delete_repository(cx));
|
.update(cx, |store, cx| store.delete_repository(cx));
|
||||||
@@ -974,7 +992,6 @@ impl RepoDetailView {
|
|||||||
} else {
|
} else {
|
||||||
"Cloning repository..."
|
"Cloning repository..."
|
||||||
};
|
};
|
||||||
|
|
||||||
return v_flex()
|
return v_flex()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.size_full()
|
.size_full()
|
||||||
@@ -1024,7 +1041,7 @@ impl RepoDetailView {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
.entries(move |_, cx| {
|
.entries(move |_, _| {
|
||||||
let mut entries = vec![
|
let mut entries = vec![
|
||||||
SidebarEntry::row("repo-nav-commits", "Commits")
|
SidebarEntry::row("repo-nav-commits", "Commits")
|
||||||
.prefix(Icon::named(IconRole::GitCommit))
|
.prefix(Icon::named(IconRole::GitCommit))
|
||||||
@@ -1053,7 +1070,10 @@ impl RepoDetailView {
|
|||||||
entries.push(SidebarEntry::header("Files"));
|
entries.push(SidebarEntry::header("Files"));
|
||||||
|
|
||||||
entries.push(SidebarEntry::custom(
|
entries.push(SidebarEntry::custom(
|
||||||
files.read(cx).render_tree(files.downgrade()),
|
files
|
||||||
|
.clone()
|
||||||
|
.cached(StyleRefinement::default().flex_1().min_h_0().w_full())
|
||||||
|
.into_any_element(),
|
||||||
));
|
));
|
||||||
|
|
||||||
entries
|
entries
|
||||||
@@ -1078,7 +1098,6 @@ impl RepoDetailView {
|
|||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
actions::open_repo_panel(&self.workspace, &addr, None, window, cx);
|
actions::open_repo_panel(&self.workspace, &addr, None, window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1087,13 +1106,9 @@ impl RepoDetailView {
|
|||||||
let Some(local_path) = self.store.read(cx).path.clone() else {
|
let Some(local_path) = self.store.read(cx).path.clone() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
self.init = Some(dialogs::init::InitRepoDialog::new(
|
let view = cx.entity().downgrade();
|
||||||
local_path,
|
let dialog = InitRepoDialog::new(local_path, view, window, cx);
|
||||||
cx.entity().downgrade(),
|
cx.open_dialog(dialog);
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
));
|
|
||||||
cx.notify();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn render_about(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
pub(super) fn render_about(&mut self, cx: &mut Context<Self>) -> AnyElement {
|
||||||
@@ -1106,9 +1121,10 @@ impl RepoDetailView {
|
|||||||
let pushing = store.pushing;
|
let pushing = store.pushing;
|
||||||
let cloning = store.cloning;
|
let cloning = store.cloning;
|
||||||
|
|
||||||
let Some(announcement) = store.announcement.clone() else {
|
let Some(header) = &self.header else {
|
||||||
return div().into_any_element();
|
return div().into_any_element();
|
||||||
};
|
};
|
||||||
|
let announcement = header.announcement.as_ref();
|
||||||
|
|
||||||
let nip05 = self
|
let nip05 = self
|
||||||
.directory
|
.directory
|
||||||
@@ -1119,23 +1135,22 @@ impl RepoDetailView {
|
|||||||
.clone()
|
.clone()
|
||||||
.filter(|nip05| !nip05.trim().is_empty());
|
.filter(|nip05| !nip05.trim().is_empty());
|
||||||
|
|
||||||
let nostr_url = nostr_clone_url(&announcement, nip05.as_deref());
|
let nostr_url = nostr_clone_url(announcement, nip05.as_deref());
|
||||||
let ngit_command = SharedString::from(format!("git clone {nostr_url}"));
|
let ngit_command = SharedString::from(format!("git clone {nostr_url}"));
|
||||||
let nak_command = SharedString::from(format!("nak git clone {nostr_url}"));
|
let nak_command = SharedString::from(format!("nak git clone {nostr_url}"));
|
||||||
let git_commands: Vec<String> = announcement.clone_urls();
|
|
||||||
|
|
||||||
let name = repo_display_name(self.store.read(cx));
|
let name = repo_display_name(self.store.read(cx));
|
||||||
let description = announcement.description();
|
let description = announcement.description();
|
||||||
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id));
|
let avatar = Avatar::new(format!("{}:{}", announcement.owner, announcement.id));
|
||||||
|
|
||||||
let announcement_for_menu = announcement.clone();
|
let announcement_for_menu = Arc::clone(&header.announcement);
|
||||||
let weak_menu_open = cx.entity().downgrade();
|
let weak_menu_open = cx.entity().downgrade();
|
||||||
let weak_menu_items = cx.entity().downgrade();
|
let weak_menu_items = cx.entity().downgrade();
|
||||||
let weak_clone = cx.entity().downgrade();
|
let weak_clone = cx.entity().downgrade();
|
||||||
let weak_download = cx.entity().downgrade();
|
let weak_download = cx.entity().downgrade();
|
||||||
let ngit_for_popover = ngit_command.clone();
|
let ngit_for_popover = ngit_command.clone();
|
||||||
let nak_for_popover = nak_command.clone();
|
let nak_for_popover = nak_command.clone();
|
||||||
let git_for_popover = git_commands.clone();
|
let git_for_popover = Arc::clone(&header.git_commands);
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.p_6()
|
.p_6()
|
||||||
@@ -1170,7 +1185,7 @@ impl RepoDetailView {
|
|||||||
.line_clamp(3)
|
.line_clamp(3)
|
||||||
.child(description),
|
.child(description),
|
||||||
)
|
)
|
||||||
.when_some(fork_row(&announcement, cx), |this, row| this.child(row)),
|
.when_some(fork_row(announcement, cx), |this, row| this.child(row)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
@@ -1280,20 +1295,21 @@ impl RepoDetailView {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.items(move |_, cx| {
|
.items(move |_, cx| {
|
||||||
let owner = backend.read(cx).current_user()
|
let current_user = backend.read(cx).current_user();
|
||||||
== Some(announcement_for_menu.owner);
|
let owner = current_user == Some(announcement_for_menu.owner);
|
||||||
|
|
||||||
let mut items = vec![MenuItem::new("About").handler({
|
let mut items = vec![MenuItem::new("About").handler({
|
||||||
let weak = weak_menu_items.clone();
|
let weak = weak_menu_items.clone();
|
||||||
let announcement = announcement_for_menu.clone();
|
let announcement = Arc::clone(&announcement_for_menu);
|
||||||
|
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
if let Err(error) = weak.update(cx, |this, cx| {
|
if let Err(error) = weak.update(cx, |this, cx| {
|
||||||
this.about = Some(dialogs::about::AboutDialog::new(
|
let dialog = dialogs::about::AboutDialog::new(
|
||||||
announcement.clone(),
|
Arc::clone(&announcement),
|
||||||
this.directory.clone(),
|
this.directory.clone(),
|
||||||
cx,
|
cx,
|
||||||
));
|
);
|
||||||
cx.notify();
|
cx.open_dialog(dialog);
|
||||||
}) {
|
}) {
|
||||||
log::warn!("failed to open about: {error}");
|
log::warn!("failed to open about: {error}");
|
||||||
}
|
}
|
||||||
@@ -1325,11 +1341,14 @@ impl RepoDetailView {
|
|||||||
items.push(MenuItem::new("Delete").destructive(true).handler(
|
items.push(MenuItem::new("Delete").destructive(true).handler(
|
||||||
{
|
{
|
||||||
let weak = weak_menu_items.clone();
|
let weak = weak_menu_items.clone();
|
||||||
move |window, cx| {
|
move |_window, cx| {
|
||||||
if let Err(error) = weak.update(cx, |this, cx| {
|
if let Err(error) = weak.update(cx, |_, cx| {
|
||||||
this.delete_repository(window, cx);
|
let view = cx.entity().downgrade();
|
||||||
|
let dialog =
|
||||||
|
DeleteRepositoryDialog::new(view, cx);
|
||||||
|
cx.open_dialog(dialog);
|
||||||
}) {
|
}) {
|
||||||
log::warn!("failed to delete: {error}");
|
log::warn!("failed to ask to delete: {error}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1553,9 +1572,6 @@ impl Panel for RepoDetailView {
|
|||||||
|
|
||||||
impl Render for RepoDetailView {
|
impl Render for RepoDetailView {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let weak = cx.entity().downgrade();
|
|
||||||
let sync_weak = cx.entity().downgrade();
|
|
||||||
|
|
||||||
let error = self.error.clone().or_else(|| {
|
let error = self.error.clone().or_else(|| {
|
||||||
self.store
|
self.store
|
||||||
.read(cx)
|
.read(cx)
|
||||||
@@ -1570,6 +1586,7 @@ impl Render for RepoDetailView {
|
|||||||
.child(self.render_about(cx))
|
.child(self.render_about(cx))
|
||||||
.child(self.render_metadata(cx))
|
.child(self.render_metadata(cx))
|
||||||
.when_some(error, |this, error| {
|
.when_some(error, |this, error| {
|
||||||
|
let weak = cx.entity().downgrade();
|
||||||
this.child(
|
this.child(
|
||||||
Alert::new("repo-error")
|
Alert::new("repo-error")
|
||||||
.severity(AlertSeverity::Danger)
|
.severity(AlertSeverity::Danger)
|
||||||
@@ -1605,38 +1622,5 @@ impl Render for RepoDetailView {
|
|||||||
.child(self.render_pane(cx)),
|
.child(self.render_pane(cx)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.when_some(self.about.clone(), |el, view| el.child(view))
|
|
||||||
.when_some(self.init.clone(), |el, view| el.child(view))
|
|
||||||
.when_some(self.reset.clone(), |el, view| el.child(view))
|
|
||||||
.when_some(self.sync_error.clone(), |el, error| {
|
|
||||||
el.child(
|
|
||||||
Dialog::new("sync-error-dialog")
|
|
||||||
.alert(true)
|
|
||||||
.open(true)
|
|
||||||
.title("Sync failed")
|
|
||||||
.content(move |_, cx| {
|
|
||||||
div()
|
|
||||||
.text_base()
|
|
||||||
.text_color(cx.theme().colors.muted_foreground)
|
|
||||||
.child(error.clone())
|
|
||||||
.into_any_element()
|
|
||||||
})
|
|
||||||
.actions(move |_, _| {
|
|
||||||
let sync_weak = sync_weak.clone();
|
|
||||||
vec![
|
|
||||||
Button::new("close-sync-error")
|
|
||||||
.label("Close")
|
|
||||||
.variant(ButtonVariant::Secondary)
|
|
||||||
.on_click(move |_, _, cx| {
|
|
||||||
log_dropped(sync_weak.update(cx, |this, cx| {
|
|
||||||
this.sync_error = None;
|
|
||||||
cx.notify();
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.into_any_element(),
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,25 +141,20 @@ pub fn grasp_servers_editor(input: &Entity<InputState>, cx: &App) -> AnyElement
|
|||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.children(servers.iter().enumerate().map(|(ix, server)| {
|
.children(servers.iter().map(|server| {
|
||||||
let server = server.clone();
|
let server = server.clone();
|
||||||
editor_value_row(
|
editor_value_row(
|
||||||
format!("settings-remove-server:{ix}"),
|
format!("settings-remove-server:{server}"),
|
||||||
display_server(&server),
|
display_server(&server),
|
||||||
move |cx| {
|
move |cx| {
|
||||||
let store = SettingsStore::global(cx);
|
let store = SettingsStore::global(cx);
|
||||||
store.update(cx, |store, cx| {
|
store.update(cx, |store, cx| {
|
||||||
store.edit(
|
store.edit(
|
||||||
|settings| {
|
|settings| {
|
||||||
// A row's index can desync after a prior removal; match by value.
|
settings
|
||||||
if let Some(at) = settings
|
|
||||||
.grasp_servers
|
.grasp_servers
|
||||||
.default_servers
|
.default_servers
|
||||||
.iter()
|
.retain(|known| known != &server);
|
||||||
.position(|known| known == &server)
|
|
||||||
{
|
|
||||||
settings.grasp_servers.default_servers.remove(at);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
@@ -233,25 +228,20 @@ pub fn scan_paths_editor(cx: &App) -> AnyElement {
|
|||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.children(scan_paths.iter().enumerate().map(|(ix, path)| {
|
.children(scan_paths.iter().map(|path| {
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
editor_value_row(
|
editor_value_row(
|
||||||
format!("settings-remove-path:{ix}"),
|
format!("settings-remove-path:{}", path.display()),
|
||||||
SharedString::from(path.display().to_string()),
|
SharedString::from(path.display().to_string()),
|
||||||
move |cx| {
|
move |cx| {
|
||||||
let store = SettingsStore::global(cx);
|
let store = SettingsStore::global(cx);
|
||||||
store.update(cx, |store, cx| {
|
store.update(cx, |store, cx| {
|
||||||
store.edit(
|
store.edit(
|
||||||
|settings| {
|
|settings| {
|
||||||
// A row's index can desync after a prior removal; match by value.
|
settings
|
||||||
if let Some(at) = settings
|
|
||||||
.local_repos
|
.local_repos
|
||||||
.scan_paths
|
.scan_paths
|
||||||
.iter()
|
.retain(|known| known != &path);
|
||||||
.position(|known| known == &path)
|
|
||||||
{
|
|
||||||
settings.local_repos.scan_paths.remove(at);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -312,6 +312,9 @@ impl RenderOnce for Dialog {
|
|||||||
.read(cx)
|
.read(cx)
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
|
// The panel takes focus when it first paints, and again whenever nothing else holds it.
|
||||||
|
let painted = window.use_keyed_state((self.id.clone(), "dialog-painted"), cx, |_, _| false);
|
||||||
|
|
||||||
deferred(
|
deferred(
|
||||||
root.flex()
|
root.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
@@ -442,8 +445,11 @@ impl RenderOnce for Dialog {
|
|||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
canvas(|_, _, _| {}, {
|
canvas(|_, _, _| {}, {
|
||||||
|
let painted = painted.clone();
|
||||||
move |_, _, window, cx| {
|
move |_, _, window, cx| {
|
||||||
if !focus.contains_focused(window, cx) {
|
let first_paint = painted
|
||||||
|
.update(cx, |painted, _| !std::mem::replace(painted, true));
|
||||||
|
if first_paint || window.focused(cx).is_none() {
|
||||||
window.focus(&focus, cx);
|
window.focus(&focus, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1005,11 +1005,6 @@ impl InputState {
|
|||||||
/// with the paint-time text style. Reuses the previous result while the
|
/// with the paint-time text style. Reuses the previous result while the
|
||||||
/// text, wrap width, and text style are unchanged.
|
/// text, wrap width, and text style are unchanged.
|
||||||
fn shape_current_text(&self, wrap_width: Option<Pixels>, window: &Window) -> ShapedText {
|
fn shape_current_text(&self, wrap_width: Option<Pixels>, window: &Window) -> ShapedText {
|
||||||
let (text, mask_map) = if self.masked() {
|
|
||||||
masked_display(&self.text)
|
|
||||||
} else {
|
|
||||||
(self.text.clone(), None)
|
|
||||||
};
|
|
||||||
let text_style = window.text_style();
|
let text_style = window.text_style();
|
||||||
|
|
||||||
let font = Font {
|
let font = Font {
|
||||||
@@ -1022,6 +1017,23 @@ impl InputState {
|
|||||||
|
|
||||||
let font_size = text_style.font_size.to_pixels(window.rem_size());
|
let font_size = text_style.font_size.to_pixels(window.rem_size());
|
||||||
|
|
||||||
|
if !self.masked()
|
||||||
|
&& let Some((cached_key, shaped)) = self.shaped_cache.borrow().as_ref()
|
||||||
|
&& cached_key.text == self.text
|
||||||
|
&& cached_key.wrap_width == wrap_width
|
||||||
|
&& cached_key.font_size == font_size
|
||||||
|
&& cached_key.font == font
|
||||||
|
&& cached_key.color == text_style.color
|
||||||
|
{
|
||||||
|
return shaped.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
let (text, mask_map) = if self.masked() {
|
||||||
|
masked_display(&self.text)
|
||||||
|
} else {
|
||||||
|
(self.text.clone(), None)
|
||||||
|
};
|
||||||
|
|
||||||
let key = ShapeCacheKey {
|
let key = ShapeCacheKey {
|
||||||
text: text.clone(),
|
text: text.clone(),
|
||||||
wrap_width,
|
wrap_width,
|
||||||
@@ -1030,12 +1042,6 @@ impl InputState {
|
|||||||
color: text_style.color,
|
color: text_style.color,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((cached_key, shaped)) = self.shaped_cache.borrow().as_ref()
|
|
||||||
&& *cached_key == key
|
|
||||||
{
|
|
||||||
return shaped.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
let runs = [TextRun {
|
let runs = [TextRun {
|
||||||
len: text.len(),
|
len: text.len(),
|
||||||
font,
|
font,
|
||||||
@@ -2022,6 +2028,13 @@ impl RenderOnce for Input {
|
|||||||
let padding_x = self.size.padding_x_rems().to_pixels(rem);
|
let padding_x = self.size.padding_x_rems().to_pixels(rem);
|
||||||
let dense_padding_x = self.size.dense_padding_x_rems().to_pixels(rem);
|
let dense_padding_x = self.size.dense_padding_x_rems().to_pixels(rem);
|
||||||
let focus_handle = self.state.read(cx).focus_handle.clone();
|
let focus_handle = self.state.read(cx).focus_handle.clone();
|
||||||
|
let owner = window.current_view();
|
||||||
|
let state = self.state.clone();
|
||||||
|
|
||||||
|
window.use_keyed_state((self.id.clone(), "input-owner"), cx, |_, cx| {
|
||||||
|
// Edits must repaint the view that renders the field, even below a cached view.
|
||||||
|
App::observe(cx, &state, move |_, cx| cx.notify(owner))
|
||||||
|
});
|
||||||
let focused = focus_handle.is_focused(window);
|
let focused = focus_handle.is_focused(window);
|
||||||
|
|
||||||
let is_empty = self.state.read(cx).text.is_empty();
|
let is_empty = self.state.read(cx).text.is_empty();
|
||||||
@@ -2634,35 +2647,3 @@ fn floor_to_char_boundary(text: &str, index: usize) -> usize {
|
|||||||
}
|
}
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[allow(clippy::reversed_empty_ranges)] // The fixture is intentionally reversed.
|
|
||||||
fn utf16_range_to_utf8_orders_reversed_endpoints() {
|
|
||||||
// "héllo": h 0, é 1, l 2, l 3, o 4 in UTF-16 units.
|
|
||||||
let text = "héllo";
|
|
||||||
assert_eq!(utf16_range_to_utf8(text, 4..2), 3..5);
|
|
||||||
assert_eq!(utf16_range_to_utf8(text, 2..4), 3..5);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[allow(clippy::reversed_empty_ranges)] // The fixture is intentionally reversed.
|
|
||||||
fn utf8_range_to_utf16_floors_off_boundary_offsets() {
|
|
||||||
let text = "héllo";
|
|
||||||
// Byte 2 sits inside `é`; a reversed, off-boundary range must not panic.
|
|
||||||
let range = utf8_range_to_utf16(text, 4..2);
|
|
||||||
assert!(range.start <= range.end);
|
|
||||||
assert_eq!(range, 1..3);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn char_boundary_floor_clamps_to_len() {
|
|
||||||
// "héllo" is six bytes.
|
|
||||||
assert_eq!(floor_to_char_boundary("héllo", 7), 6);
|
|
||||||
assert_eq!(floor_to_char_boundary("héllo", 2), 1);
|
|
||||||
assert_eq!(floor_to_char_boundary("héllo", 0), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -460,7 +460,14 @@ impl Tab {
|
|||||||
.group_hover(group.clone(), |style| style.visible()),
|
.group_hover(group.clone(), |style| style.visible()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(!titlebar, |label| label.child(self.label.clone()));
|
.when(!titlebar, |label| {
|
||||||
|
label
|
||||||
|
.min_w_0()
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.overflow_hidden()
|
||||||
|
.text_ellipsis()
|
||||||
|
.child(self.label.clone())
|
||||||
|
});
|
||||||
|
|
||||||
let strip_tab = div()
|
let strip_tab = div()
|
||||||
.id((self.key.clone(), "tab"))
|
.id((self.key.clone(), "tab"))
|
||||||
@@ -485,9 +492,9 @@ impl Tab {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.map(|strip_tab| {
|
.map(|strip_tab| {
|
||||||
apply_tab_chrome(strip_tab, ctx.variant, active, cx).when(titlebar, |strip_tab| {
|
apply_tab_chrome(strip_tab, ctx.variant, active, cx)
|
||||||
strip_tab.min_w(TAB_MIN_WIDTH).max_w(TAB_MAX_WIDTH)
|
.max_w(TAB_MAX_WIDTH)
|
||||||
})
|
.when(titlebar, |strip_tab| strip_tab.min_w(TAB_MIN_WIDTH))
|
||||||
})
|
})
|
||||||
.when_some(self.lead.take(), |strip_tab, lead| strip_tab.child(lead))
|
.when_some(self.lead.take(), |strip_tab, lead| strip_tab.child(lead))
|
||||||
.child(label)
|
.child(label)
|
||||||
|
|||||||
@@ -3,14 +3,16 @@
|
|||||||
//! # Examples
|
//! # Examples
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
|
//! use std::sync::Arc;
|
||||||
|
//!
|
||||||
//! use ui::tree::{Tree, TreeItem};
|
//! use ui::tree::{Tree, TreeItem};
|
||||||
//!
|
//!
|
||||||
//! let project = Tree::new("project")
|
//! let project = Tree::new("project")
|
||||||
//! .items(|_, _| {
|
//! .items(|_, _| {
|
||||||
//! vec![
|
//! Arc::new(vec![
|
||||||
//! TreeItem::new("src", "src").expandable(true).expanded(true),
|
//! TreeItem::new("src", "src").expandable(true).expanded(true),
|
||||||
//! TreeItem::new("main", "main.rs").depth(1),
|
//! TreeItem::new("main", "main.rs").depth(1),
|
||||||
//! ]
|
//! ])
|
||||||
//! })
|
//! })
|
||||||
//! .on_change(|_selected, _window, _cx| println!("selection changed"));
|
//! .on_change(|_selected, _window, _cx| println!("selection changed"));
|
||||||
//! ```
|
//! ```
|
||||||
@@ -18,6 +20,7 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@@ -37,7 +40,7 @@ type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>;
|
|||||||
/// The disclosure reporter, fired with the toggled row's index.
|
/// The disclosure reporter, fired with the toggled row's index.
|
||||||
type DisclosureHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;
|
type DisclosureHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;
|
||||||
/// The visible row builder, run during render.
|
/// The visible row builder, run during render.
|
||||||
type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<TreeItem>>;
|
type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Arc<Vec<TreeItem>>>;
|
||||||
|
|
||||||
/// The deepest indent the tree paints, bounding misbuilt item trees.
|
/// The deepest indent the tree paints, bounding misbuilt item trees.
|
||||||
const TREE_MAX_DEPTH: usize = 16;
|
const TREE_MAX_DEPTH: usize = 16;
|
||||||
@@ -192,6 +195,10 @@ impl TreeItem {
|
|||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.overflow_hidden()
|
||||||
|
.text_ellipsis()
|
||||||
.text_color(label_color)
|
.text_color(label_color)
|
||||||
.child(self.label.clone()),
|
.child(self.label.clone()),
|
||||||
)
|
)
|
||||||
@@ -465,7 +472,7 @@ impl Tree {
|
|||||||
/// Sets the visible rows; the closure runs during render and must not mutate entities or notify.
|
/// Sets the visible rows; the closure runs during render and must not mutate entities or notify.
|
||||||
pub fn items<F>(mut self, items: F) -> Self
|
pub fn items<F>(mut self, items: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&mut Window, &mut App) -> Vec<TreeItem> + 'static,
|
F: Fn(&mut Window, &mut App) -> Arc<Vec<TreeItem>> + 'static,
|
||||||
{
|
{
|
||||||
self.items = Some(Box::new(items));
|
self.items = Some(Box::new(items));
|
||||||
self
|
self
|
||||||
@@ -546,7 +553,7 @@ impl RenderOnce for Tree {
|
|||||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
let items = match self.items {
|
let items = match self.items {
|
||||||
Some(build) => build(window, cx),
|
Some(build) => build(window, cx),
|
||||||
None => Vec::new(),
|
None => Arc::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let selectable: Vec<usize> = items
|
let selectable: Vec<usize> = items
|
||||||
|
|||||||
@@ -401,19 +401,16 @@ impl PanelStack {
|
|||||||
|
|
||||||
/// The main stack's tab strip for the titlebar; `None` while the stack is empty.
|
/// The main stack's tab strip for the titlebar; `None` while the stack is empty.
|
||||||
pub fn main_tabs(stack: Entity<Self>, cx: &App) -> Option<Tabs> {
|
pub fn main_tabs(stack: Entity<Self>, cx: &App) -> Option<Tabs> {
|
||||||
let (id, panels, selected) = {
|
let (id, selected) = {
|
||||||
let this = stack.read(cx);
|
let this = stack.read(cx);
|
||||||
if this.main.is_empty() {
|
if this.main.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
(
|
(this.id.clone(), this.main.selected().unwrap_or(usize::MAX))
|
||||||
this.id.clone(),
|
|
||||||
this.main.panels.clone(),
|
|
||||||
this.main.selected().unwrap_or(usize::MAX),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
let change = stack.downgrade();
|
let change = stack.downgrade();
|
||||||
let close = change.clone();
|
let close = change.clone();
|
||||||
|
let tabs = change.clone();
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
Tabs::new((id, "main-tabs"))
|
Tabs::new((id, "main-tabs"))
|
||||||
@@ -421,11 +418,16 @@ impl PanelStack {
|
|||||||
.overflow_scroll(true)
|
.overflow_scroll(true)
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.tabs(move |_, cx| {
|
.tabs(move |_, cx| {
|
||||||
panels
|
tabs.read_with(cx, |stack, cx| {
|
||||||
|
stack
|
||||||
|
.main
|
||||||
|
.panels
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, panel)| panel.tab(id.clone().into(), cx).closeable(true))
|
.map(|(id, panel)| panel.tab(id.clone().into(), cx).closeable(true))
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
.on_change(move |index, _, cx| {
|
.on_change(move |index, _, cx| {
|
||||||
change
|
change
|
||||||
.update(cx, |stack, cx| {
|
.update(cx, |stack, cx| {
|
||||||
@@ -539,10 +541,10 @@ impl PanelStack {
|
|||||||
|
|
||||||
/// The split pane's content: the split stack's tabs over its shown panel.
|
/// The split pane's content: the split stack's tabs over its shown panel.
|
||||||
fn split_pane(&self, cx: &mut Context<Self>) -> AnyElement {
|
fn split_pane(&self, cx: &mut Context<Self>) -> AnyElement {
|
||||||
let panels: Vec<(SharedString, Arc<dyn PanelView>)> = self.split.panels.clone();
|
|
||||||
let selected = self.split.selected().unwrap_or(usize::MAX);
|
let selected = self.split.selected().unwrap_or(usize::MAX);
|
||||||
let change = cx.weak_entity();
|
let change = cx.weak_entity();
|
||||||
let close = change.clone();
|
let close = change.clone();
|
||||||
|
let tabs = change.clone();
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.size_full()
|
.size_full()
|
||||||
@@ -554,11 +556,18 @@ impl PanelStack {
|
|||||||
.overflow_scroll(true)
|
.overflow_scroll(true)
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.tabs(move |_, cx| {
|
.tabs(move |_, cx| {
|
||||||
panels
|
tabs.read_with(cx, |stack, cx| {
|
||||||
|
stack
|
||||||
|
.split
|
||||||
|
.panels
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, panel)| panel.tab(id.clone().into(), cx).closeable(true))
|
.map(|(id, panel)| {
|
||||||
|
panel.tab(id.clone().into(), cx).closeable(true)
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
.on_change(move |index, _, cx| {
|
.on_change(move |index, _, cx| {
|
||||||
change
|
change
|
||||||
.update(cx, |stack, cx| {
|
.update(cx, |stack, cx| {
|
||||||
@@ -574,11 +583,11 @@ impl PanelStack {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
div()
|
div().flex_1().min_h_0().w_full().children(
|
||||||
.flex_1()
|
self.split
|
||||||
.min_h_0()
|
.active()
|
||||||
.w_full()
|
.map(|panel| panel.view().cached(content_style()).into_any_element()),
|
||||||
.children(self.split.active().map(|panel| panel.view())),
|
),
|
||||||
)
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -504,9 +504,13 @@ pub(crate) fn reapply(cx: &mut App) {
|
|||||||
let resolved = resolve::resolve(&system, preset.as_ref(), mode_override, custom);
|
let resolved = resolve::resolve(&system, preset.as_ref(), mode_override, custom);
|
||||||
|
|
||||||
cx.set_reduce_motion(resolved.accessibility.reduce_motion);
|
cx.set_reduce_motion(resolved.accessibility.reduce_motion);
|
||||||
cx.set_global(Theme::from_resolved(resolved));
|
let theme = Theme::from_resolved(resolved);
|
||||||
|
let theme_changed = cx.try_global::<Theme>() != Some(&theme);
|
||||||
|
cx.set_global(theme);
|
||||||
|
if theme_changed {
|
||||||
cx.refresh_windows();
|
cx.refresh_windows();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Forces a variant, independent of the OS. `None` follows the system.
|
/// Forces a variant, independent of the OS. `None` follows the system.
|
||||||
pub fn set_mode_override(variant: Option<ThemeVariant>, cx: &mut App) {
|
pub fn set_mode_override(variant: Option<ThemeVariant>, cx: &mut App) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
//! The panel stack: the main island fills the window; splitting makes two
|
//! The panel stack: the main island fills the window; splitting makes two
|
||||||
//! half-width islands with a drag divider that resizes them.
|
//! half-width islands with a drag divider that resizes them.
|
||||||
|
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@@ -10,6 +12,7 @@ use gpui::{
|
|||||||
size,
|
size,
|
||||||
};
|
};
|
||||||
use ui::common::v_flex;
|
use ui::common::v_flex;
|
||||||
|
use ui::input::{Input, InputState};
|
||||||
use ui::layout::panel::{Panel, PanelSlot, PanelStack, PanelView, SplitSide};
|
use ui::layout::panel::{Panel, PanelSlot, PanelStack, PanelView, SplitSide};
|
||||||
use ui::tabs::Tabs;
|
use ui::tabs::Tabs;
|
||||||
use ui::theme::Theme;
|
use ui::theme::Theme;
|
||||||
@@ -69,6 +72,28 @@ impl Render for PanelHarness {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A split panel that counts its renders around a field.
|
||||||
|
struct FieldView {
|
||||||
|
input: Entity<InputState>,
|
||||||
|
renders: Rc<Cell<usize>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for FieldView {
|
||||||
|
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.renders.set(self.renders.get() + 1);
|
||||||
|
div()
|
||||||
|
.debug_selector(|| "panel-test-field".to_string())
|
||||||
|
.size_full()
|
||||||
|
.child(Input::new("split-field", self.input.clone()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for FieldView {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
"Field".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A marker view.
|
/// A marker view.
|
||||||
fn tag(cx: &mut App, selector: &'static str) -> Entity<TagView> {
|
fn tag(cx: &mut App, selector: &'static str) -> Entity<TagView> {
|
||||||
cx.new(|_| TagView::new(selector))
|
cx.new(|_| TagView::new(selector))
|
||||||
@@ -989,3 +1014,49 @@ fn zoom_ends_when_another_split_panel_is_shown(cx: &mut TestAppContext) {
|
|||||||
"the split is back once another panel is shown"
|
"the split is back once another panel is shown"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The split panel is cached: it repaints for its own changes, not for other panels'.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_split_panel_repaints_for_its_own_changes_only(cx: &mut TestAppContext) {
|
||||||
|
let renders = Rc::new(Cell::new(0));
|
||||||
|
let (input, main, field) = cx.update(|cx| {
|
||||||
|
let input = InputState::new(cx);
|
||||||
|
let field = cx.new(|_| FieldView {
|
||||||
|
input: input.clone(),
|
||||||
|
renders: Rc::clone(&renders),
|
||||||
|
});
|
||||||
|
(input, tag(cx, "panel-test-main"), field)
|
||||||
|
});
|
||||||
|
let seeded_main = main.clone();
|
||||||
|
let seeded_field = field.clone();
|
||||||
|
let (mut cx, _stack) = stack_window(cx, move |stack, cx| {
|
||||||
|
stack.insert(PanelSlot::Main, "main", Arc::new(seeded_main), cx);
|
||||||
|
stack.insert(PanelSlot::Split, "split", Arc::new(seeded_field), cx);
|
||||||
|
});
|
||||||
|
let rendered = renders.get();
|
||||||
|
|
||||||
|
cx.update(|window, cx| input.update(cx, |input, cx| input.set_value("hey", window, cx)));
|
||||||
|
cx.run_until_parked();
|
||||||
|
let typed = cx.update(|_, cx| input.read(cx).value().to_string());
|
||||||
|
assert_eq!(typed, "hey");
|
||||||
|
assert!(
|
||||||
|
renders.get() > rendered,
|
||||||
|
"an edit in the split panel repaints it"
|
||||||
|
);
|
||||||
|
|
||||||
|
let rendered = renders.get();
|
||||||
|
cx.update(|_, cx| main.update(cx, |_, cx| cx.notify()));
|
||||||
|
cx.run_until_parked();
|
||||||
|
assert_eq!(
|
||||||
|
renders.get(),
|
||||||
|
rendered,
|
||||||
|
"another panel's change leaves the split panel as it was"
|
||||||
|
);
|
||||||
|
|
||||||
|
cx.update(|_, cx| field.update(cx, |_, cx| cx.notify()));
|
||||||
|
cx.run_until_parked();
|
||||||
|
assert!(
|
||||||
|
renders.get() > rendered,
|
||||||
|
"the split panel's own change repaints it"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user