Fix focus handle leak (#26090)
This fixes a major performance issue in the current git beta. This PR also removes the PopoverButton component, which was easy to misuse. Release Notes: - Git Beta: Fix frame drops caused by opening the git panel --------- Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
fe18c73a07
commit
674fb7621f
13 changed files with 276 additions and 459 deletions
|
@ -1,7 +1,6 @@
|
|||
use crate::branch_picker::{self, BranchList};
|
||||
use crate::branch_picker::{self};
|
||||
use crate::git_panel_settings::StatusStyle;
|
||||
use crate::remote_output_toast::{RemoteAction, RemoteOutputToast};
|
||||
use crate::repository_selector::RepositorySelectorPopoverMenu;
|
||||
use crate::{
|
||||
git_panel_settings::GitPanelSettings, git_status_icon, repository_selector::RepositorySelector,
|
||||
};
|
||||
|
@ -41,8 +40,8 @@ use std::{collections::HashSet, sync::Arc, time::Duration, usize};
|
|||
use strum::{IntoEnumIterator, VariantNames};
|
||||
use time::OffsetDateTime;
|
||||
use ui::{
|
||||
prelude::*, ButtonLike, Checkbox, ContextMenu, ElevationIndex, PopoverButton, PopoverMenu,
|
||||
Scrollbar, ScrollbarState, Tooltip,
|
||||
prelude::*, ButtonLike, Checkbox, ContextMenu, ElevationIndex, PopoverMenu, Scrollbar,
|
||||
ScrollbarState, Tooltip,
|
||||
};
|
||||
use util::{maybe, post_inc, ResultExt, TryFutureExt};
|
||||
|
||||
|
@ -206,7 +205,6 @@ pub struct GitPanel {
|
|||
pending_commit: Option<Task<()>>,
|
||||
pending_serialization: Task<Option<()>>,
|
||||
pub(crate) project: Entity<Project>,
|
||||
repository_selector: Entity<RepositorySelector>,
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
scrollbar_state: ScrollbarState,
|
||||
selected_entry: Option<usize>,
|
||||
|
@ -311,9 +309,6 @@ impl GitPanel {
|
|||
let scrollbar_state =
|
||||
ScrollbarState::new(scroll_handle.clone()).parent_entity(&cx.entity());
|
||||
|
||||
let repository_selector =
|
||||
cx.new(|cx| RepositorySelector::new(project.clone(), window, cx));
|
||||
|
||||
let mut git_panel = Self {
|
||||
pending_remote_operations: Default::default(),
|
||||
remote_operation_id: 0,
|
||||
|
@ -333,7 +328,6 @@ impl GitPanel {
|
|||
pending_commit: None,
|
||||
pending_serialization: Task::ready(None),
|
||||
project,
|
||||
repository_selector,
|
||||
scroll_handle,
|
||||
scrollbar_state,
|
||||
selected_entry: None,
|
||||
|
@ -2039,14 +2033,13 @@ impl GitPanel {
|
|||
.display_name(project, cx)
|
||||
.trim_end_matches("/"),
|
||||
));
|
||||
let branches = branch_picker::popover(self.project.clone(), window, cx);
|
||||
|
||||
let footer = v_flex()
|
||||
.child(PanelRepoFooter::new(
|
||||
"footer-button",
|
||||
display_name,
|
||||
branch,
|
||||
Some(git_panel),
|
||||
Some(branches),
|
||||
))
|
||||
.child(
|
||||
panel_editor_container(window, cx)
|
||||
|
@ -3072,7 +3065,6 @@ pub struct PanelRepoFooter {
|
|||
//
|
||||
// For now just take an option here, and we won't bind handlers to buttons in previews.
|
||||
git_panel: Option<Entity<GitPanel>>,
|
||||
branches: Option<Entity<BranchList>>,
|
||||
}
|
||||
|
||||
impl PanelRepoFooter {
|
||||
|
@ -3081,14 +3073,12 @@ impl PanelRepoFooter {
|
|||
active_repository: SharedString,
|
||||
branch: Option<Branch>,
|
||||
git_panel: Option<Entity<GitPanel>>,
|
||||
branches: Option<Entity<BranchList>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
active_repository,
|
||||
branch,
|
||||
git_panel,
|
||||
branches,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3102,7 +3092,6 @@ impl PanelRepoFooter {
|
|||
active_repository,
|
||||
branch,
|
||||
git_panel: None,
|
||||
branches: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3324,7 +3313,7 @@ impl PanelRepoFooter {
|
|||
}
|
||||
|
||||
impl RenderOnce for PanelRepoFooter {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let active_repo = self.active_repository.clone();
|
||||
let overflow_menu_id: SharedString = format!("overflow-menu-{}", active_repo).into();
|
||||
let repo_selector_trigger = Button::new("repo-selector", active_repo)
|
||||
|
@ -3333,29 +3322,36 @@ impl RenderOnce for PanelRepoFooter {
|
|||
.label_size(LabelSize::Small)
|
||||
.color(Color::Muted);
|
||||
|
||||
let repo_selector = if let Some(panel) = self.git_panel.clone() {
|
||||
let repo_selector = panel.read(cx).repository_selector.clone();
|
||||
let repo_count = repo_selector.read(cx).repositories_len(cx);
|
||||
let single_repo = repo_count == 1;
|
||||
let project = self
|
||||
.git_panel
|
||||
.as_ref()
|
||||
.map(|panel| panel.read(cx).project.clone());
|
||||
|
||||
RepositorySelectorPopoverMenu::new(
|
||||
panel.read(cx).repository_selector.clone(),
|
||||
let single_repo = project
|
||||
.as_ref()
|
||||
.map(|project| project.read(cx).all_repositories(cx).len() == 1)
|
||||
.unwrap_or(true);
|
||||
|
||||
let repo_selector = PopoverMenu::new("repository-switcher")
|
||||
.menu({
|
||||
let project = project.clone();
|
||||
move |window, cx| {
|
||||
let project = project.clone()?;
|
||||
Some(cx.new(|cx| RepositorySelector::new(project, window, cx)))
|
||||
}
|
||||
})
|
||||
.trigger_with_tooltip(
|
||||
repo_selector_trigger.disabled(single_repo).truncate(true),
|
||||
Tooltip::text("Switch active repository"),
|
||||
)
|
||||
.into_any_element()
|
||||
} else {
|
||||
// for rendering preview, we don't have git_panel there
|
||||
repo_selector_trigger.into_any_element()
|
||||
};
|
||||
.attach(gpui::Corner::BottomLeft)
|
||||
.into_any_element();
|
||||
|
||||
let branch = self.branch.clone();
|
||||
let branch_name = branch
|
||||
.as_ref()
|
||||
.map_or(" (no branch)".into(), |branch| branch.name.clone());
|
||||
|
||||
let branches = self.branches.clone();
|
||||
|
||||
let branch_selector_button = Button::new("branch-selector", branch_name)
|
||||
.style(ButtonStyle::Transparent)
|
||||
.size(ButtonSize::None)
|
||||
|
@ -3369,18 +3365,17 @@ impl RenderOnce for PanelRepoFooter {
|
|||
window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx);
|
||||
});
|
||||
|
||||
let branch_selector = if let Some(branches) = branches {
|
||||
PopoverButton::new(
|
||||
branches,
|
||||
Corner::BottomLeft,
|
||||
let branch_selector = PopoverMenu::new("popover-button")
|
||||
.menu(move |window, cx| Some(branch_picker::popover(project.clone()?, window, cx)))
|
||||
.trigger_with_tooltip(
|
||||
branch_selector_button,
|
||||
Tooltip::for_action_title("Switch Branch", &zed_actions::git::Branch),
|
||||
)
|
||||
.render(window, cx)
|
||||
.into_any_element()
|
||||
} else {
|
||||
branch_selector_button.into_any_element()
|
||||
};
|
||||
.anchor(Corner::TopLeft)
|
||||
.offset(gpui::Point {
|
||||
x: px(0.0),
|
||||
y: px(-2.0),
|
||||
});
|
||||
|
||||
let spinner = self
|
||||
.git_panel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue