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.

Limit editor rendering to visible clipped rows (#58132)

Lukas Wirthfd93a53c1702
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index 026a3032a1c..5474e6e3cb1 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -7997,12 +7997,14 @@ impl Element for EditorElement {
// Calculate how much of the editor is clipped by parent containers (e.g., List).
// This allows us to only render lines that are actually visible, which is
- // critical for performance when large AutoHeight editors are inside Lists.
+ // critical for performance when large content-sized editors are inside Lists.
let visible_bounds = window.content_mask().bounds;
- let clipped_top = (visible_bounds.origin.y - bounds.origin.y).max(px(0.));
+ let visible_top = bounds.top().max(visible_bounds.top());
+ let visible_bottom = bounds.bottom().min(visible_bounds.bottom());
+ let clipped_top = (visible_top - bounds.top()).max(px(0.));
+ let visible_height = (visible_bottom - visible_top).max(px(0.));
let clipped_top_in_lines = f64::from(clipped_top / line_height);
- let visible_height_in_lines =
- f64::from(visible_bounds.size.height / line_height);
+ let visible_height_in_lines = f64::from(visible_height / line_height);
// The max scroll position for the top of the window
let scroll_beyond_last_line = self.editor.read(cx).scroll_beyond_last_line(cx);