Skip to content

Commit

Permalink
Primary cursor colors by mode (helix-editor#5130)
Browse files Browse the repository at this point in the history
* (theme) feat: mode based primary cursor colors

* docs/themes: mode based primary cursor colors
  • Loading branch information
gibbz00 authored and Shafkath Shuhan committed Jan 24, 2023
1 parent a378992 commit 14ed67a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,14 @@ These scopes are used for theming the editor interface.
| `ui.background` | |
| `ui.background.separator` | Picker separator below input line |
| `ui.cursor` | |
| `ui.cursor.normal` | |
| `ui.cursor.insert` | |
| `ui.cursor.select` | |
| `ui.cursor.match` | Matching bracket etc. |
| `ui.cursor.primary` | Cursor with primary selection |
| `ui.cursor.primary.normal` | |
| `ui.cursor.primary.insert` | |
| `ui.cursor.primary.select` | |
| `ui.gutter` | Gutter |
| `ui.gutter.selected` | Gutter for the line the cursor is on |
| `ui.linenr` | Line numbers |
Expand Down
20 changes: 13 additions & 7 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,23 +342,29 @@ impl EditorView {
let selection_scope = theme
.find_scope_index("ui.selection")
.expect("could not find `ui.selection` scope in the theme!");
let primary_selection_scope = theme
.find_scope_index("ui.selection.primary")
.unwrap_or(selection_scope);
let base_cursor_scope = theme
.find_scope_index("ui.cursor")
.unwrap_or(selection_scope);
let base_primary_cursor_scope = theme
.find_scope_index("ui.cursor.primary")
.unwrap_or(base_cursor_scope);

let cursor_scope = match mode {
Mode::Insert => theme.find_scope_index("ui.cursor.insert"),
Mode::Select => theme.find_scope_index("ui.cursor.select"),
Mode::Normal => Some(base_cursor_scope),
Mode::Normal => theme.find_scope_index("ui.cursor.normal"),
}
.unwrap_or(base_cursor_scope);

let primary_cursor_scope = theme
.find_scope_index("ui.cursor.primary")
.unwrap_or(cursor_scope);
let primary_selection_scope = theme
.find_scope_index("ui.selection.primary")
.unwrap_or(selection_scope);
let primary_cursor_scope = match mode {
Mode::Insert => theme.find_scope_index("ui.cursor.primary.insert"),
Mode::Select => theme.find_scope_index("ui.cursor.primary.select"),
Mode::Normal => theme.find_scope_index("ui.cursor.primary.normal"),
}
.unwrap_or(base_primary_cursor_scope);

let mut spans: Vec<(usize, std::ops::Range<usize>)> = Vec::new();
for (i, range) in selection.iter().enumerate() {
Expand Down

0 comments on commit 14ed67a

Please sign in to comment.