Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Fix debug selectors with cached views (#64433)

Cameron Mcloughlin94c997e06faa
diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs
index 126c406c788..c730ef27221 100644
--- a/crates/gpui/src/elements/div.rs
+++ b/crates/gpui/src/elements/div.rs
@@ -2522,8 +2522,7 @@ impl Interactivity {
if let Some(debug_selector) = &self.debug_selector {
window
.next_frame
- .debug_bounds
- .insert(debug_selector.clone(), bounds);
+ .record_debug_bounds(debug_selector.clone(), bounds);
}
self.paint_hover_group_handler(window, cx);
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index 6794bb3c81b..45fabc3c943 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -991,6 +991,8 @@ pub(crate) struct Frame {
pub(crate) cursor_styles: Vec<CursorStyleRequest>,
#[cfg(any(test, feature = "test-support"))]
pub(crate) debug_bounds: FxHashMap<String, Bounds<Pixels>>,
+ #[cfg(any(test, feature = "test-support"))]
+ debug_bounds_records: Vec<(String, Bounds<Pixels>)>,
#[cfg(any(feature = "inspector", debug_assertions))]
pub(crate) next_inspector_instance_ids: FxHashMap<Rc<crate::InspectorElementPath>, usize>,
#[cfg(any(feature = "inspector", debug_assertions))]
@@ -1011,6 +1013,8 @@ pub(crate) struct PrepaintStateIndex {
#[derive(Clone, Default)]
pub(crate) struct PaintIndex {
scene_index: usize,
+ #[cfg(any(test, feature = "test-support"))]
+ debug_bounds_index: usize,
mouse_listeners_index: usize,
input_handlers_index: usize,
cursor_styles_index: usize,
@@ -1020,6 +1024,12 @@ pub(crate) struct PaintIndex {
}
impl Frame {
+ #[cfg(any(test, feature = "test-support"))]
+ pub(crate) fn record_debug_bounds(&mut self, selector: String, bounds: Bounds<Pixels>) {
+ self.debug_bounds.insert(selector.clone(), bounds);
+ self.debug_bounds_records.push((selector, bounds));
+ }
+
pub(crate) fn new(dispatch_tree: DispatchTree) -> Self {
Frame {
focus: None,
@@ -1038,6 +1048,8 @@ impl Frame {
#[cfg(any(test, feature = "test-support"))]
debug_bounds: FxHashMap::default(),
+ #[cfg(any(test, feature = "test-support"))]
+ debug_bounds_records: Vec::new(),
#[cfg(any(feature = "inspector", debug_assertions))]
next_inspector_instance_ids: FxHashMap::default(),
@@ -1066,6 +1078,7 @@ impl Frame {
#[cfg(any(test, feature = "test-support"))]
{
self.debug_bounds.clear();
+ self.debug_bounds_records.clear();
}
#[cfg(any(feature = "inspector", debug_assertions))]
@@ -3860,6 +3873,8 @@ impl Window {
pub(crate) fn paint_index(&self) -> PaintIndex {
PaintIndex {
scene_index: self.next_frame.scene.len(),
+ #[cfg(any(test, feature = "test-support"))]
+ debug_bounds_index: self.next_frame.debug_bounds_records.len(),
mouse_listeners_index: self.next_frame.mouse_listeners.len(),
input_handlers_index: self.next_frame.input_handlers.len(),
cursor_styles_index: self.next_frame.cursor_styles.len(),
@@ -3870,6 +3885,14 @@ impl Window {
}
pub(crate) fn reuse_paint(&mut self, range: Range<PaintIndex>) {
+ // Cached elements still exist in the frame even when their paint methods don't run.
+ #[cfg(any(test, feature = "test-support"))]
+ for (selector, bounds) in &self.rendered_frame.debug_bounds_records
+ [range.start.debug_bounds_index..range.end.debug_bounds_index]
+ {
+ self.next_frame
+ .record_debug_bounds(selector.clone(), *bounds);
+ }
self.next_frame.cursor_styles.extend(
self.rendered_frame.cursor_styles
[range.start.cursor_styles_index..range.end.cursor_styles_index]