From d5a24953282d65f1ebd13bf7ee5dd93cf162f417 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 21:51:08 +0000 Subject: [PATCH] editor: Fix relative line numbering with deleted blocks present (#49656) (cherry-pick to stable) (#49658) Cherry-pick of #49656 to stable ---- This tackles another issue where we would incorrectly show two absolute line numbers with relative line numbering enabled when it really should only have been the current active line number. Sadly, no tests rn for this as we would need a better test infra for that to properly catch/test this bug. But with the refactored logic, I think this is easier to understand at glance, so at least theres that Release Notes: - Fixed an issue with relative line numbers where some rows would be missing their relative line number with deleted hunks showing. Co-authored-by: Finn Evers --- crates/editor/src/editor.rs | 23 +++++++++-------------- crates/editor/src/editor_tests.rs | 1 + 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7a67abfeb6427181610d3382ff06062932bb1680..4c827cfbb0c404b2f67ab0677432f4d01d3d37cf 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -27558,7 +27558,6 @@ impl EditorSnapshot { ) -> HashMap { let initial_offset = self.relative_line_delta(current_selection_head, rows.start, count_wrapped_lines); - let current_selection_point = current_selection_head.as_display_point().to_point(self); self.row_infos(rows.start) .take(rows.len()) @@ -27569,23 +27568,19 @@ impl EditorSnapshot { || (count_wrapped_lines && row_info.wrapped_buffer_row.is_some()) }) .enumerate() - .filter(|(_, (row, row_info))| { - // We want to check here that - // - the row is not the current selection head to ensure the current - // line has absolute numbering - // - similarly, should the selection head live in a soft-wrapped line - // and we are not counting those, that the parent line keeps its - // absolute number - // - lastly, if we are in a deleted line, it is fine to number this + .filter_map(|(i, (row, row_info))| { + // We want to ensure here that the current line has absolute + // numbering, even if we are in a soft-wrapped line. With the + // exception that if we are in a deleted line, we should number this // relative with 0, as otherwise it would have no line number at all - (*row != current_selection_head - && (count_wrapped_lines - || row_info.buffer_row != Some(current_selection_point.row))) + let relative_line_number = (initial_offset + i as i64).unsigned_abs() as u32; + + (relative_line_number != 0 || row_info .diff_status - .is_some_and(|status| status.is_deleted()) + .is_some_and(|status| status.is_deleted())) + .then_some((row, relative_line_number)) }) - .map(|(i, (row, _))| (row, (initial_offset + i as i64).unsigned_abs() as u32)) .collect() } } diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 997058fbd8c41fd98743fc9a783c97332bcc1ddb..793d058ca2afb020713065afcd43aaba977e2f37 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -29127,6 +29127,7 @@ fn test_relative_line_numbers(cx: &mut TestAppContext) { .into_iter() .enumerate() .map(|(i, row)| (DisplayRow(row), i.abs_diff(base_row) as u32)) + .filter(|(_, relative_line_number)| *relative_line_number != 0) .collect_vec(); let actual_relative_numbers = snapshot .calculate_relative_line_numbers(