chore: Avoid some unnecessary window.refresh call. (#617)

Ref
https://github.com/zed-industries/zed/discussions/24260#discussioncomment-12135749
This commit is contained in:
Jason Lee 2025-02-11 17:06:17 +08:00 committed by GitHub
parent 4a26776289
commit 0050685a58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 51 additions and 56 deletions

View file

@ -1,4 +1,3 @@
use core::time;
use std::time::Duration;
use fake::Fake;
@ -306,22 +305,19 @@ impl ListStory {
// Spawn a background to random refresh the list
cx.spawn(move |this, mut cx| async move {
loop {
Timer::after(time::Duration::from_secs_f64(0.5)).await;
this.update(&mut cx, |this, cx| {
this.company_list.update(cx, |picker, _| {
picker
.delegate_mut()
.companies
.iter_mut()
.for_each(|company| {
company.random_update();
});
});
cx.notify();
})
.ok();
}
this.update(&mut cx, |this, cx| {
this.company_list.update(cx, |picker, _| {
picker
.delegate_mut()
.companies
.iter_mut()
.for_each(|company| {
company.random_update();
});
});
cx.notify();
})
.ok();
})
.detach();

View file

@ -3,10 +3,10 @@
use std::sync::Arc;
use gpui::{
div, prelude::FluentBuilder as _, px, AnyView, App, AppContext, Axis, Context, Element, Empty,
Entity, InteractiveElement as _, IntoElement, MouseMoveEvent, MouseUpEvent, ParentElement as _,
Pixels, Point, Render, StatefulInteractiveElement, Style, StyleRefinement, Styled as _,
WeakEntity, Window,
div, prelude::FluentBuilder as _, px, App, AppContext, Axis, Context, Element, Empty, Entity,
InteractiveElement as _, IntoElement, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels,
Point, Render, StatefulInteractiveElement, Style, StyleRefinement, Styled as _, WeakEntity,
Window,
};
use serde::{Deserialize, Serialize};
@ -411,9 +411,7 @@ impl Render for Dock {
})
.map(|this| match &self.panel {
DockItem::Split { view, .. } => this.child(view.clone()),
DockItem::Tabs { view, .. } => {
this.child(AnyView::from(view.clone()).cached(cache_style))
}
DockItem::Tabs { view, .. } => this.child(view.clone()),
DockItem::Panel { view, .. } => this.child(view.clone().view().cached(cache_style)),
// Not support to render Tiles and Tile into Dock
DockItem::Tiles { .. } => this,
@ -472,14 +470,20 @@ impl Element for DockElement {
_: &mut Self::RequestLayoutState,
_: &mut Self::PrepaintState,
window: &mut gpui::Window,
_: &mut App,
cx: &mut App,
) {
window.on_mouse_event({
let view = self.view.clone();
let is_resizing = view.read(cx).is_resizing;
move |e: &MouseMoveEvent, phase, window, cx| {
if phase.bubble() {
view.update(cx, |view, cx| view.resize(e.position, window, cx))
if !is_resizing {
return;
}
if !phase.bubble() {
return;
}
view.update(cx, |view, cx| view.resize(e.position, window, cx))
}
});

View file

@ -143,7 +143,6 @@ impl PopupMenu {
scroll_state: Rc::new(Cell::new(ScrollbarState::default())),
_subscriptions,
};
window.refresh();
f(menu, window, cx)
})
}

View file

@ -496,41 +496,38 @@ impl Element for ResizePanelGroupElement {
let axis = self.axis;
let current_ix = view.read(cx).resizing_panel_ix;
move |e: &MouseMoveEvent, phase, window, cx| {
if phase.bubble() {
if let Some(ix) = current_ix {
view.update(cx, |view, cx| {
let panel = view
.panels
.get(ix)
.expect("BUG: invalid panel index")
.read(cx);
match axis {
Axis::Horizontal => view.resize_panels(
ix,
e.position.x - panel.bounds.left(),
window,
cx,
),
Axis::Vertical => {
view.resize_panels(
ix,
e.position.y - panel.bounds.top(),
window,
cx,
);
}
}
})
}
if !phase.bubble() {
return;
}
let Some(ix) = current_ix else { return };
view.update(cx, |view, cx| {
let panel = view
.panels
.get(ix)
.expect("BUG: invalid panel index")
.read(cx);
match axis {
Axis::Horizontal => {
view.resize_panels(ix, e.position.x - panel.bounds.left(), window, cx)
}
Axis::Vertical => {
view.resize_panels(ix, e.position.y - panel.bounds.top(), window, cx);
}
}
})
}
});
// When any mouse up, stop dragging
window.on_mouse_event({
let view = self.view.clone();
let current_ix = view.read(cx).resizing_panel_ix;
move |_: &MouseUpEvent, phase, window, cx| {
if current_ix.is_none() {
return;
}
if phase.bubble() {
view.update(cx, |view, cx| view.done_resizing(window, cx));
}

View file

@ -124,7 +124,6 @@ impl RenderOnce for WindowBorder {
.when(!tiling.bottom, |div| div.pb(SHADOW_SIZE))
.when(!tiling.left, |div| div.pl(SHADOW_SIZE))
.when(!tiling.right, |div| div.pr(SHADOW_SIZE))
.on_mouse_move(|_e, window, _| window.refresh())
.on_mouse_down(MouseButton::Left, move |_, window, _| {
let size = window.window_bounds().get_bounds().size;
let pos = window.mouse_position();