Reduce display_map snapshot creation (#39354)
Re-applies https://github.com/zed-industries/zed/pull/30840 This PR re-applies the initial [PR](https://github.com/zed-industries/zed/pull/30840). As it was closed because it was hard to land, because of the many conflicts. This PR re-applies the changes for it. In several cases we were creating multiple display_map snapshots within the same root-level function call. Creating a display_map snapshot is quite slow, and in some cases we were creating the snapshot multiple times. Release Notes: - N/A
This commit is contained in:
@@ -72,7 +72,12 @@ impl Editor {
|
||||
cx: &mut Context<Editor>,
|
||||
) {
|
||||
let scroll_margin_rows = self.vertical_scroll_margin() as u32;
|
||||
let new_screen_top = self.selections.newest_display(cx).head().row().0;
|
||||
let new_screen_top = self
|
||||
.selections
|
||||
.newest_display(&self.display_snapshot(cx))
|
||||
.head()
|
||||
.row()
|
||||
.0;
|
||||
let new_screen_top = new_screen_top.saturating_sub(scroll_margin_rows);
|
||||
self.set_scroll_top_row(DisplayRow(new_screen_top), window, cx);
|
||||
}
|
||||
@@ -86,7 +91,12 @@ impl Editor {
|
||||
let Some(visible_rows) = self.visible_line_count().map(|count| count as u32) else {
|
||||
return;
|
||||
};
|
||||
let new_screen_top = self.selections.newest_display(cx).head().row().0;
|
||||
let new_screen_top = self
|
||||
.selections
|
||||
.newest_display(&self.display_snapshot(cx))
|
||||
.head()
|
||||
.row()
|
||||
.0;
|
||||
let new_screen_top = new_screen_top.saturating_sub(visible_rows / 2);
|
||||
self.set_scroll_top_row(DisplayRow(new_screen_top), window, cx);
|
||||
}
|
||||
@@ -101,7 +111,12 @@ impl Editor {
|
||||
let Some(visible_rows) = self.visible_line_count().map(|count| count as u32) else {
|
||||
return;
|
||||
};
|
||||
let new_screen_top = self.selections.newest_display(cx).head().row().0;
|
||||
let new_screen_top = self
|
||||
.selections
|
||||
.newest_display(&self.display_snapshot(cx))
|
||||
.head()
|
||||
.row()
|
||||
.0;
|
||||
let new_screen_top =
|
||||
new_screen_top.saturating_sub(visible_rows.saturating_sub(scroll_margin_rows));
|
||||
self.set_scroll_top_row(DisplayRow(new_screen_top), window, cx);
|
||||
|
||||
@@ -148,7 +148,7 @@ impl Editor {
|
||||
target_top = first_highlighted_row.as_f64();
|
||||
target_bottom = target_top + 1.;
|
||||
} else {
|
||||
let selections = self.selections.all::<Point>(cx);
|
||||
let selections = self.selections.all::<Point>(&display_map);
|
||||
|
||||
target_top = selections
|
||||
.first()
|
||||
@@ -293,7 +293,7 @@ impl Editor {
|
||||
let scroll_width = ScrollOffset::from(scroll_width);
|
||||
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let selections = self.selections.all::<Point>(cx);
|
||||
let selections = self.selections.all::<Point>(&display_map);
|
||||
let mut scroll_position = self.scroll_manager.scroll_position(&display_map);
|
||||
|
||||
let mut target_left;
|
||||
|
||||
Reference in New Issue
Block a user