Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix run indicators jumping when buffer content changes. (#25507)
Conrad Irwin7b277d2efdb2
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex d24b43ea0fb..67fdc790c01 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -524,7 +524,7 @@ impl ScrollbarMarkerState {#[derive(Clone, Debug)]struct RunnableTasks {templates: Vec<(TaskSourceKind, TaskTemplate)>,- offset: MultiBufferOffset,+ offset: multi_buffer::Anchor,// We need the column at which the task context evaluation should take place (when we're spawning it via gutter).column: u32,// Values of all named captures, including those starting with '_'@@ -551,8 +551,6 @@ struct ResolvedTasks {templates: SmallVec<[(TaskSourceKind, ResolvedTask); 1]>,position: Anchor,}-#[derive(Copy, Clone, Debug)]-struct MultiBufferOffset(usize);#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]struct BufferOffset(usize);@@ -10848,7 +10846,9 @@ impl Editor {(runnable.buffer_id, row),RunnableTasks {templates: tasks,- offset: MultiBufferOffset(runnable.run_range.start),+ offset: snapshot+ .buffer_snapshot+ .anchor_before(runnable.run_range.start),context_range,column: point.column,extra_variables: runnable.extra_captures,diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex dc5173c8e08..13380c45dd0 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -15337,11 +15337,12 @@ async fn test_find_enclosing_node_with_task(cx: &mut TestAppContext) {});editor.update_in(cx, |editor, window, cx| {+ let snapshot = editor.buffer().read(cx).snapshot(cx);editor.tasks.insert((buffer.read(cx).remote_id(), 3),RunnableTasks {templates: vec![],- offset: MultiBufferOffset(43),+ offset: snapshot.anchor_before(43),column: 0,extra_variables: HashMap::default(),context_range: BufferOffset(43)..BufferOffset(85),@@ -15351,7 +15352,7 @@ async fn test_find_enclosing_node_with_task(cx: &mut TestAppContext) {(buffer.read(cx).remote_id(), 8),RunnableTasks {templates: vec![],- offset: MultiBufferOffset(86),+ offset: snapshot.anchor_before(86),column: 0,extra_variables: HashMap::default(),context_range: BufferOffset(86)..BufferOffset(191),diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 7d791777afe..a0c0efe5ee3 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -50,7 +50,7 @@ use language::{use lsp::DiagnosticSeverity;use multi_buffer::{Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, MultiBufferPoint, MultiBufferRow,- RowInfo, ToOffset,+ RowInfo,};use project::project_settings::{self, GitGutterSetting, ProjectSettings};use settings::Settings;@@ -2062,21 +2062,22 @@ impl EditorElement {None};- let offset_range_start = snapshot- .display_point_to_anchor(DisplayPoint::new(range.start, 0), Bias::Left)- .to_offset(&snapshot.buffer_snapshot);- let offset_range_end = snapshot- .display_point_to_anchor(DisplayPoint::new(range.end, 0), Bias::Right)- .to_offset(&snapshot.buffer_snapshot);+ let offset_range_start =+ snapshot.display_point_to_point(DisplayPoint::new(range.start, 0), Bias::Left);++ let offset_range_end =+ snapshot.display_point_to_point(DisplayPoint::new(range.end, 0), Bias::Right);editor.tasks.iter().filter_map(|(_, tasks)| {- if tasks.offset.0 < offset_range_start || tasks.offset.0 >= offset_range_end {+ let multibuffer_point = tasks.offset.to_point(&snapshot.buffer_snapshot);+ if multibuffer_point < offset_range_start+ || multibuffer_point > offset_range_end+ {return None;}- let multibuffer_point = tasks.offset.0.to_point(&snapshot.buffer_snapshot);let multibuffer_row = MultiBufferRow(multibuffer_point.row);let buffer_folded = snapshot.buffer_snapshot