From 3017afd965610eb20b05f1ec28c1e0982c8a852b Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 08:48:54 +0000 Subject: [PATCH] multi_buffer: Bring `update_path_excerpts` ordering workaround back (#49563) (cherry-pick to preview) (#49567) Cherry-pick of #49563 to preview ---- cc https://github.com/zed-industries/zed/pull/49290 Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored-by: Lukas Wirth --- crates/multi_buffer/src/path_key.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/multi_buffer/src/path_key.rs b/crates/multi_buffer/src/path_key.rs index eb65da13eeaae70af96e74844f6420b3584330ad..be2b7bfa33954b6d8a19c42b544822cb1608aaef 100644 --- a/crates/multi_buffer/src/path_key.rs +++ b/crates/multi_buffer/src/path_key.rs @@ -471,16 +471,25 @@ impl MultiBuffer { } self.insert_excerpts_with_ids_after(insert_after, buffer, to_insert, cx); + // todo(lw): There is a logic bug somewhere that causes the to_remove vector to be not ordered correctly + to_remove.sort_by_cached_key(|&id| snapshot.excerpt_locator_for_id(id)); self.remove_excerpts(to_remove, cx); if excerpt_ids.is_empty() { self.excerpts_by_path.remove(&path); } else { - for excerpt_id in &excerpt_ids { - self.paths_by_excerpt.insert(*excerpt_id, path.clone()); + let snapshot = &*self.snapshot.get_mut(); + let excerpt_ids = excerpt_ids + .iter() + .dedup() + .cloned() + // todo(lw): There is a logic bug somewhere that causes excerpt_ids to not necessarily be in order by locator + .sorted_by_cached_key(|&id| snapshot.excerpt_locator_for_id(id)) + .collect(); + for &excerpt_id in &excerpt_ids { + self.paths_by_excerpt.insert(excerpt_id, path.clone()); } - self.excerpts_by_path - .insert(path, excerpt_ids.iter().dedup().cloned().collect()); + self.excerpts_by_path.insert(path, excerpt_ids); } PathExcerptInsertResult {