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:
Conrad Irwin 2025-03-04 17:50:26 -07:00 committed by GitHub
parent fe18c73a07
commit 674fb7621f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 276 additions and 459 deletions

View file

@ -19,7 +19,6 @@ mod modal;
mod navigable;
mod numeric_stepper;
mod popover;
mod popover_button;
mod popover_menu;
mod radio;
mod right_click_menu;
@ -57,7 +56,6 @@ pub use modal::*;
pub use navigable::*;
pub use numeric_stepper::*;
pub use popover::*;
pub use popover_button::*;
pub use popover_menu::*;
pub use radio::*;
pub use right_click_menu::*;

View file

@ -1,57 +0,0 @@
use gpui::{AnyView, Corner, Entity, ManagedView};
use crate::{prelude::*, PopoverMenu, PopoverMenuHandle, PopoverTrigger};
pub trait TriggerablePopover: ManagedView {
fn menu_handle(
&mut self,
window: &mut Window,
cx: &mut gpui::Context<Self>,
) -> PopoverMenuHandle<Self>;
}
pub struct PopoverButton<T, B, F> {
selector: Entity<T>,
button: B,
tooltip: F,
corner: Corner,
}
impl<T, B, F> PopoverButton<T, B, F> {
pub fn new(selector: Entity<T>, corner: Corner, button: B, tooltip: F) -> Self
where
F: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
Self {
selector,
button,
tooltip,
corner,
}
}
}
impl<T: TriggerablePopover, B: PopoverTrigger + ButtonCommon, F> RenderOnce
for PopoverButton<T, B, F>
where
F: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let menu_handle = self
.selector
.update(cx, |selector, cx| selector.menu_handle(window, cx));
PopoverMenu::new("popover-button")
.menu({
let selector = self.selector.clone();
move |_window, _cx| Some(selector.clone())
})
.trigger_with_tooltip(self.button, self.tooltip)
.anchor(self.corner)
.with_handle(menu_handle)
.offset(gpui::Point {
x: px(0.0),
y: px(-2.0),
})
}
}