Skip to content

Commit

Permalink
Current line highlight options
Browse files Browse the repository at this point in the history
  • Loading branch information
alygin committed May 11, 2024
1 parent 48cba32 commit 6a3b892
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 13 deletions.
2 changes: 2 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"drop_target_size": 0.2,
// Whether the cursor blinks in the editor.
"cursor_blink": true,
// How to highlight the current line in the editor.
"current_line_highlight": "all",
// Whether to pop the completions menu while typing in an editor without
// explicitly requesting it.
"show_completions_on_input": true,
Expand Down
18 changes: 18 additions & 0 deletions crates/editor/src/editor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use settings::{Settings, SettingsSources};
#[derive(Deserialize, Clone)]
pub struct EditorSettings {
pub cursor_blink: bool,
pub current_line_highlight: CurrentLineHighlight,
pub hover_popover_enabled: bool,
pub show_completions_on_input: bool,
pub show_completion_documentation: bool,
Expand All @@ -24,6 +25,19 @@ pub struct EditorSettings {
pub double_click_in_multibuffer: DoubleClickInMultibuffer,
}

#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CurrentLineHighlight {
// Don't highlight the current line.
None,
// Highlight the gutter area.
Gutter,
// Highlight the editor area.
Line,
// Highlight the full line.
All,
}

/// When to populate a new search's query based on the text under the cursor.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -105,6 +119,10 @@ pub struct EditorSettingsContent {
///
/// Default: true
pub cursor_blink: Option<bool>,
/// How to highlight the current line in the editor.
///
/// Default: all
pub current_line_highlight: Option<CurrentLineHighlight>,
/// Whether to show the informational hover box when moving the mouse
/// over symbols in the editor.
///
Expand Down
49 changes: 36 additions & 13 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::{
BlockContext, BlockStyle, DisplaySnapshot, FoldStatus, HighlightedChunk, ToDisplayPoint,
TransformBlock,
},
editor_settings::{DoubleClickInMultibuffer, MultiCursorModifier, ShowScrollbar},
editor_settings::{
CurrentLineHighlight, DoubleClickInMultibuffer, MultiCursorModifier, ShowScrollbar,
},
git::{blame::GitBlame, diff_hunk_to_display, DisplayDiffHunk},
hover_popover::{
self, hover_at, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
Expand Down Expand Up @@ -2287,18 +2289,39 @@ impl EditorElement {
}

if !contains_non_empty_selection {
let origin = point(
layout.hitbox.origin.x,
layout.hitbox.origin.y
+ (start_row.as_f32() - scroll_top)
* layout.position_map.line_height,
);
let size = size(
layout.hitbox.size.width,
layout.position_map.line_height * (end_row - start_row.0 + 1) as f32,
);
let active_line_bg = cx.theme().colors().editor_active_line_background;
cx.paint_quad(fill(Bounds { origin, size }, active_line_bg));
let highlight_h_range =
match EditorSettings::get_global(cx).current_line_highlight {
CurrentLineHighlight::Gutter => Some(Range {
start: layout.hitbox.left(),
end: layout.gutter_hitbox.right(),
}),
CurrentLineHighlight::Line => Some(Range {
start: layout.text_hitbox.bounds.left(),
end: layout.text_hitbox.bounds.right(),
}),
CurrentLineHighlight::All => Some(Range {
start: layout.hitbox.left(),
end: layout.hitbox.right(),
}),
CurrentLineHighlight::None => None,
};
if let Some(range) = highlight_h_range {
let active_line_bg = cx.theme().colors().editor_active_line_background;
let bounds = Bounds {
origin: point(
range.start,
layout.hitbox.origin.y
+ (start_row.as_f32() - scroll_top)
* layout.position_map.line_height,
),
size: size(
range.end - range.start,
layout.position_map.line_height
* (end_row - start_row.0 + 1) as f32,
),
};
cx.paint_quad(fill(bounds, active_line_bg));
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions docs/src/configuring-zed.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,38 @@ left and right padding of the central pane from the workspace when the centered

List of `string` values

## Current Line Highlight

- Description: How to highlight the current line in the editor.
- Setting: `current_line_highlight`
- Default: `all`

**Options**

1. Don't highlight the current line:

```json
"current_line_highlight": "none"
```

2. Highlight the gutter area.

```json
"current_line_highlight": "gutter"
```

3. Highlight the editor area.

```json
"current_line_highlight": "line"
```

4. Highlight the full line.

```json
"current_line_highlight": "all"
```

## Cursor Blink

- Description: Whether or not the cursor blinks.
Expand Down

0 comments on commit 6a3b892

Please sign in to comment.