diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index c5a64c7651bd93af2016af7224c9891706caca3a..87b096dc5c6d4872e764bc07994542d9ad4c0543 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -510,7 +510,7 @@ impl EditorElement { position_map: &PositionMap, text_hitbox: &Hitbox, gutter_hitbox: &Hitbox, - line_numbers: &HashMap)>, + line_numbers: &HashMap, cx: &mut ViewContext, ) { if cx.default_prevented() { @@ -618,22 +618,24 @@ impl EditorElement { .snapshot .display_point_to_point(DisplayPoint::new(DisplayRow(display_row), 0), Bias::Right) .row; - if let Some((_, Some(hitbox))) = line_numbers.get(&MultiBufferRow(multi_buffer_row)) { - if hitbox.contains(&event.position) { - let scroll_position_row = - position_map.scroll_pixel_position.y / position_map.line_height; - let line_offset_from_top = display_row - scroll_position_row as u32; - - editor.open_excerpts_common( - Some(JumpData::MultiBufferRow { - row: MultiBufferRow(multi_buffer_row), - line_offset_from_top, - }), - modifiers.alt, - cx, - ); - cx.stop_propagation(); - } + if line_numbers + .get(&MultiBufferRow(multi_buffer_row)) + .and_then(|line_number| line_number.hitbox.as_ref()) + .is_some_and(|hitbox| hitbox.contains(&event.position)) + { + let scroll_position_row = + position_map.scroll_pixel_position.y / position_map.line_height; + let line_offset_from_top = display_row - scroll_position_row as u32; + + editor.open_excerpts_common( + Some(JumpData::MultiBufferRow { + row: MultiBufferRow(multi_buffer_row), + line_offset_from_top, + }), + modifiers.alt, + cx, + ); + cx.stop_propagation(); } } } @@ -2033,11 +2035,10 @@ impl EditorElement { scroll_position: gpui::Point, rows: Range, buffer_rows: impl Iterator>, - active_rows: &BTreeMap, newest_selection_head: Option, snapshot: &EditorSnapshot, cx: &mut WindowContext, - ) -> Arc)>> { + ) -> Arc> { let include_line_numbers = snapshot.show_line_numbers.unwrap_or_else(|| { EditorSettings::get_global(cx).gutter.line_numbers && snapshot.mode == EditorMode::Full }); @@ -2075,19 +2076,15 @@ impl EditorElement { .enumerate() .flat_map(|(ix, buffer_row)| { let buffer_row = buffer_row?; - let display_row = DisplayRow(rows.start.0 + ix as u32); - let color = if active_rows.contains_key(&display_row) { - cx.theme().colors().editor_active_line_number - } else { - cx.theme().colors().editor_line_number - }; line_number.clear(); - let default_number = buffer_row.0 + 1; + let display_row = DisplayRow(rows.start.0 + ix as u32); + let non_relative_number = buffer_row.0 + 1; let number = relative_rows - .get(&DisplayRow(ix as u32 + rows.start.0)) - .unwrap_or(&default_number); + .get(&display_row) + .unwrap_or(&non_relative_number); write!(&mut line_number, "{number}").unwrap(); + let color = cx.theme().colors().editor_line_number; let shaped_line = self .shape_line_number(SharedString::from(&line_number), color, cx) .log_err()?; @@ -2115,7 +2112,12 @@ impl EditorElement { let multi_buffer_row = DisplayPoint::new(display_row, 0).to_point(snapshot).row; let multi_buffer_row = MultiBufferRow(multi_buffer_row); - Some((multi_buffer_row, (shaped_line, hitbox))) + let line_number = LineNumberLayout { + shaped_line, + hitbox, + display_row, + }; + Some((multi_buffer_row, line_number)) }) .collect(); Arc::new(line_numbers) @@ -3961,17 +3963,26 @@ impl EditorElement { let line_height = layout.position_map.line_height; cx.set_cursor_style(CursorStyle::Arrow, &layout.gutter_hitbox); - for (_, (line, hitbox)) in layout.line_numbers.iter() { + for LineNumberLayout { + shaped_line, + hitbox, + display_row, + } in layout.line_numbers.values() + { let Some(hitbox) = hitbox else { continue; }; - let color = if !is_singleton && hitbox.is_hovered(cx) { + + let is_active = layout.active_rows.contains_key(&display_row); + + let color = if is_active { cx.theme().colors().editor_active_line_number } else { cx.theme().colors().editor_line_number }; + let Some(line) = self - .shape_line_number(line.text.clone(), color, cx) + .shape_line_number(shaped_line.text.clone(), color, cx) .log_err() else { continue; @@ -6280,7 +6291,6 @@ impl Element for EditorElement { scroll_position, start_row..end_row, buffer_rows.iter().copied(), - &active_rows, newest_selection_head, &snapshot, cx, @@ -6991,7 +7001,7 @@ pub struct EditorLayout { active_rows: BTreeMap, highlighted_rows: BTreeMap, line_elements: SmallVec<[AnyElement; 1]>, - line_numbers: Arc)>>, + line_numbers: Arc>, display_hunks: Vec<(DisplayDiffHunk, Option)>, blamed_display_rows: Option>, inline_blame: Option, @@ -7019,6 +7029,12 @@ impl EditorLayout { } } +struct LineNumberLayout { + shaped_line: ShapedLine, + hitbox: Option, + display_row: DisplayRow, +} + struct ColoredRange { start: T, end: T, @@ -7661,7 +7677,6 @@ mod tests { gpui::Point::default(), DisplayRow(0)..DisplayRow(6), (0..6).map(MultiBufferRow).map(Some), - &Default::default(), Some(DisplayPoint::new(DisplayRow(0), 0)), &snapshot, cx, @@ -7911,7 +7926,7 @@ mod tests { state .line_numbers .get(&MultiBufferRow(0)) - .and_then(|(line, _)| line.text.as_str()), + .and_then(|line_number| line_number.shaped_line.text.as_str()), Some("1") ); } diff --git a/crates/project/src/task_store.rs b/crates/project/src/task_store.rs index 33916cfd7ba0c8b2def0cbea80c19856afb09bb5..0728526ad4687e61a676b59744111811c2742031 100644 --- a/crates/project/src/task_store.rs +++ b/crates/project/src/task_store.rs @@ -20,7 +20,7 @@ use crate::{ ProjectEnvironment, }; -#[expect(clippy::large_enum_variant)] +#[allow(clippy::large_enum_variant)] // platform-dependent warning pub enum TaskStore { Functional(StoreState), Noop,