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:
@@ -341,8 +341,10 @@ pub fn init(cx: &mut App) {
|
||||
maybe!({
|
||||
let (buffer, position, _) = editor
|
||||
.update(cx, |editor, cx| {
|
||||
let cursor_point: language::Point =
|
||||
editor.selections.newest(cx).head();
|
||||
let cursor_point: language::Point = editor
|
||||
.selections
|
||||
.newest(&editor.display_snapshot(cx))
|
||||
.head();
|
||||
|
||||
editor
|
||||
.buffer()
|
||||
@@ -392,7 +394,10 @@ pub fn init(cx: &mut App) {
|
||||
let text = editor
|
||||
.update(cx, |editor, cx| {
|
||||
editor.text_for_range(
|
||||
editor.selections.newest(cx).range(),
|
||||
editor
|
||||
.selections
|
||||
.newest(&editor.display_snapshot(cx))
|
||||
.range(),
|
||||
&mut None,
|
||||
window,
|
||||
cx,
|
||||
|
||||
@@ -963,8 +963,12 @@ mod tests {
|
||||
) {
|
||||
cx.set_state(input);
|
||||
|
||||
let buffer_position =
|
||||
cx.editor(|editor, _, cx| editor.selections.newest::<Point>(cx).start);
|
||||
let buffer_position = cx.editor(|editor, _, cx| {
|
||||
editor
|
||||
.selections
|
||||
.newest::<Point>(&editor.display_snapshot(cx))
|
||||
.start
|
||||
});
|
||||
|
||||
let snapshot = &cx.buffer_snapshot();
|
||||
|
||||
|
||||
@@ -55,7 +55,10 @@ impl StackTraceView {
|
||||
cx.subscribe_in(&editor, window, |this, editor, event, window, cx| {
|
||||
if let EditorEvent::SelectionsChanged { local: true } = event {
|
||||
let excerpt_id = editor.update(cx, |editor, cx| {
|
||||
let position: Point = editor.selections.newest(cx).head();
|
||||
let position: Point = editor
|
||||
.selections
|
||||
.newest(&editor.display_snapshot(cx))
|
||||
.head();
|
||||
|
||||
editor
|
||||
.snapshot(window, cx)
|
||||
|
||||
@@ -231,7 +231,10 @@ async fn test_save_debug_scenario_to_file(executor: BackgroundExecutor, cx: &mut
|
||||
|
||||
editor.update(cx, |editor, cx| {
|
||||
assert_eq!(
|
||||
editor.selections.newest::<Point>(cx).head(),
|
||||
editor
|
||||
.selections
|
||||
.newest::<Point>(&editor.display_snapshot(cx))
|
||||
.head(),
|
||||
Point::new(5, 2)
|
||||
)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user