From f2abde4fc31f86608bd4015d1eda72471ac92cd9 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 21:16:23 +0000 Subject: [PATCH] editor: Fix relative line numbers breaking with nested folds (#47035) (cherry-pick to stable) (#47108) Cherry-pick of #47035 to stable ---- Closes #46516 The previous fix only worked for non-nested folds, whereas this one also considers nested folds properly. Also makes this more straightforward to read. Release Notes: - Fixed an issue where relative line numbering would break with nested folds. Co-authored-by: Finn Evers --- crates/editor/src/editor.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 8784ef34f1b0eb29ea329c8576bf916164adbaa4..e655a34fd56268980664a7947931af35b6445d6f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -25492,22 +25492,18 @@ impl EditorSnapshot { let wrap_row = wrap_snapshot .make_wrap_point(first_visible_row, Bias::Left) .row(); + wrap_row.0 as i64 - base_wrap_row.0 as i64 } else { - let folds = if current_selection_head < first_visible_row { - self.folds_in_range(current_selection_head..first_visible_row) - } else { - self.folds_in_range(first_visible_row..current_selection_head) - }; - - let folded_lines = folds - .map(|fold| { - let range = fold.range.0.to_point(self); - range.end.row.saturating_sub(range.start.row) - }) - .sum::() as i64; + let fold_snapshot = self.fold_snapshot(); + let base_fold_row = fold_snapshot + .to_fold_point(self.to_inlay_point(current_selection_head), Bias::Left) + .row(); + let fold_row = fold_snapshot + .to_fold_point(self.to_inlay_point(first_visible_row), Bias::Left) + .row(); - first_visible_row.row as i64 - current_selection_head.row as i64 + folded_lines + fold_row as i64 - base_fold_row as i64 } }