diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 489f6f0a408f8e885c22b10abc9371ddd7e1312e..feab5da26b4c27fb3973fade0201c06e18a02fa5 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -263,6 +263,20 @@ impl EditorElement { }); } } + + if let Some(highlighted_row) = layout.highlighted_row { + let origin = vec2f( + bounds.origin_x(), + bounds.origin_y() + (layout.line_height * highlighted_row as f32) - scroll_top, + ); + let size = vec2f(bounds.width(), layout.line_height); + cx.scene.push_quad(Quad { + bounds: RectF::new(origin, size), + background: Some(style.highlighted_line_background), + border: Border::default(), + corner_radius: 0., + }); + } } // Draw block backgrounds @@ -729,7 +743,9 @@ impl Element for EditorElement { let mut selections = HashMap::new(); let mut active_rows = BTreeMap::new(); + let mut highlighted_row = None; self.update_view(cx.app, |view, cx| { + highlighted_row = view.highlighted_row(); for selection_set_id in view.active_selection_sets(cx).collect::>() { let mut set = Vec::new(); for selection in view.selections_in_range( @@ -786,6 +802,7 @@ impl Element for EditorElement { snapshot, style: self.settings.style.clone(), active_rows, + highlighted_row, line_layouts, line_number_layouts, block_layouts, @@ -915,6 +932,7 @@ pub struct LayoutState { style: EditorStyle, snapshot: Snapshot, active_rows: BTreeMap, + highlighted_row: Option, line_layouts: Vec, line_number_layouts: Vec>, block_layouts: Vec<(Range, BlockStyle)>, diff --git a/crates/editor/src/lib.rs b/crates/editor/src/lib.rs index 1dee47ca826192dfc16ac05b88d566fab5737e2a..340ad60081909b1cb6d663b7e2e409908f2005da 100644 --- a/crates/editor/src/lib.rs +++ b/crates/editor/src/lib.rs @@ -351,6 +351,7 @@ pub struct Editor { blinking_paused: bool, mode: EditorMode, placeholder_text: Option>, + highlighted_row: Option, } pub struct Snapshot { @@ -485,6 +486,7 @@ impl Editor { blinking_paused: false, mode: EditorMode::Full, placeholder_text: None, + highlighted_row: None, } } @@ -3248,15 +3250,19 @@ impl Editor { .text() } - // pub fn font_size(&self) -> f32 { - // self.settings.font_size - // } - pub fn set_wrap_width(&self, width: f32, cx: &mut MutableAppContext) -> bool { self.display_map .update(cx, |map, cx| map.set_wrap_width(Some(width), cx)) } + pub fn set_highlighted_row(&mut self, row: Option) { + self.highlighted_row = row; + } + + pub fn highlighted_row(&mut self) -> Option { + self.highlighted_row + } + fn next_blink_epoch(&mut self) -> usize { self.blink_epoch += 1; self.blink_epoch @@ -3426,6 +3432,7 @@ impl EditorSettings { background: Default::default(), gutter_background: Default::default(), active_line_background: Default::default(), + highlighted_line_background: Default::default(), line_number: Default::default(), line_number_active: Default::default(), selection: Default::default(), diff --git a/crates/go_to_line/src/lib.rs b/crates/go_to_line/src/lib.rs index f16740603908ccfc929f34fa49767f8751b175e3..faccdebd0078739b15d524c956fba73f93d89d08 100644 --- a/crates/go_to_line/src/lib.rs +++ b/crates/go_to_line/src/lib.rs @@ -95,11 +95,17 @@ impl GoToLine { let mut components = line_editor.trim().split(':'); let row = components.next().and_then(|row| row.parse::().ok()); let column = components.next().and_then(|row| row.parse::().ok()); - if let Some(point) = row.map(|row| Point::new(row, column.unwrap_or(0))) { + if let Some(point) = row.map(|row| { + Point::new( + row.saturating_sub(1), + column.map(|column| column.saturating_sub(1)).unwrap_or(0), + ) + }) { self.active_editor.update(cx, |active_editor, cx| { let buffer = active_editor.buffer().read(cx); let point = buffer.clip_point(point, Bias::Left); active_editor.select_ranges([point..point], Some(Autoscroll::Center), cx); + active_editor.set_highlighted_row(Some(point.row)); }); cx.notify(); } @@ -111,6 +117,12 @@ impl GoToLine { impl Entity for GoToLine { type Event = Event; + + fn release(&mut self, cx: &mut MutableAppContext) { + self.active_editor.update(cx, |editor, cx| { + editor.set_highlighted_row(None); + }) + } } impl View for GoToLine { diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index 133475426cc188fcb0d7ac8e252ed26abe2b1136..920ba7e7c99dc51ef98c9b490ba873eab9e4927f 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -223,6 +223,7 @@ pub struct EditorStyle { pub selection: SelectionStyle, pub gutter_background: Color, pub active_line_background: Color, + pub highlighted_line_background: Color, pub line_number: Color, pub line_number_active: Color, pub guest_selections: Vec, @@ -286,6 +287,7 @@ impl InputEditorStyle { selection: self.selection, gutter_background: Default::default(), active_line_background: Default::default(), + highlighted_line_background: Default::default(), line_number: Default::default(), line_number_active: Default::default(), guest_selections: Default::default(), diff --git a/crates/zed/assets/themes/_base.toml b/crates/zed/assets/themes/_base.toml index 16861b74b67946ce40bf093ef0ff0f91b50467b0..cb53226103e74dc83abefa88bd4f245e4c56fe48 100644 --- a/crates/zed/assets/themes/_base.toml +++ b/crates/zed/assets/themes/_base.toml @@ -231,6 +231,7 @@ text = "$text.1" background = "$surface.1" gutter_background = "$surface.1" active_line_background = "$state.active_line" +highlighted_line_background = "$state.highlighted_line" line_number = "$text.2.color" line_number_active = "$text.0.color" selection = "$selection.host" diff --git a/crates/zed/assets/themes/black.toml b/crates/zed/assets/themes/black.toml index d37b7905be476c8499a46e43e7f30b3e551e2385..ec51391111e67ecb9c8f8e5394cf4ae5fca55da1 100644 --- a/crates/zed/assets/themes/black.toml +++ b/crates/zed/assets/themes/black.toml @@ -37,6 +37,7 @@ bad = "#b7372e" [state] active_line = "#00000033" +highlighted_line = "#faca5033" hover = "#00000033" [editor.syntax] diff --git a/crates/zed/assets/themes/dark.toml b/crates/zed/assets/themes/dark.toml index 694e3469111890d317c1528c04143b5e36a8d37f..15850f286ab3c0293b261ae987b5ea4af8259064 100644 --- a/crates/zed/assets/themes/dark.toml +++ b/crates/zed/assets/themes/dark.toml @@ -37,6 +37,7 @@ bad = "#b7372e" [state] active_line = "#00000022" +highlighted_line = "#faca5033" hover = "#00000033" [editor.syntax] diff --git a/crates/zed/assets/themes/light.toml b/crates/zed/assets/themes/light.toml index e2bfbfb650e5c704ac306283cee949547a1a67eb..5a893368c3acc1a5f72cc194edd1595c5d63851e 100644 --- a/crates/zed/assets/themes/light.toml +++ b/crates/zed/assets/themes/light.toml @@ -37,6 +37,7 @@ bad = "#b7372e" [state] active_line = "#00000008" +highlighted_line = "#faca5033" hover = "#0000000D" [editor.syntax]