on master help sign in
Primary cursor colors by mode (#5130)

* (theme) feat: mode based primary cursor colors * docs/themes: mode based primary cursor colors

commitdeae13f404fadddf16f7c2005af8b383a1d8e362 authorgibbz00 <gabrielhansson00@gmail.com> dateWed 18 Jan 2023, 06:18 (4 years ago) parentb65f104
2 files changed+17−7
book/src/themes.md+4 helix-term/src/ui/editor.rs+13−7
book/src/themes.md+4
@@ -252,10 +252,14 @@ These scopes are used for theming the editor interface.
252252| `ui.background` | |
253253| `ui.background.separator` | Picker separator below input line |
254254| `ui.cursor` | |
255+| `ui.cursor.normal` | |
255256| `ui.cursor.insert` | |
256257| `ui.cursor.select` | |
257258| `ui.cursor.match` | Matching bracket etc. |
258259| `ui.cursor.primary` | Cursor with primary selection |
260+| `ui.cursor.primary.normal` | |
261+| `ui.cursor.primary.insert` | |
262+| `ui.cursor.primary.select` | |
259263| `ui.gutter` | Gutter |
260264| `ui.gutter.selected` | Gutter for the line the cursor is on |
261265| `ui.linenr` | Line numbers |
helix-term/src/ui/editor.rs+13−7
@@ -342,23 +342,29 @@ impl EditorView {
342342 let selection_scope = theme
343343 .find_scope_index("ui.selection")
344344 .expect("could not find `ui.selection` scope in the theme!");
345+ let primary_selection_scope = theme
346+ .find_scope_index("ui.selection.primary")
347+ .unwrap_or(selection_scope);
345348 let base_cursor_scope = theme
346349 .find_scope_index("ui.cursor")
347350 .unwrap_or(selection_scope);
351+ let base_primary_cursor_scope = theme
352+ .find_scope_index("ui.cursor.primary")
353+ .unwrap_or(base_cursor_scope);
348354
349355 let cursor_scope = match mode {
350356 Mode::Insert => theme.find_scope_index("ui.cursor.insert"),
351357 Mode::Select => theme.find_scope_index("ui.cursor.select"),
352− Mode::Normal => Some(base_cursor_scope),
358+ Mode::Normal => theme.find_scope_index("ui.cursor.normal"),
353359 }
354360 .unwrap_or(base_cursor_scope);
355361
356− let primary_cursor_scope = theme
357− .find_scope_index("ui.cursor.primary")
358− .unwrap_or(cursor_scope);
359− let primary_selection_scope = theme
360− .find_scope_index("ui.selection.primary")
361− .unwrap_or(selection_scope);
362+ let primary_cursor_scope = match mode {
363+ Mode::Insert => theme.find_scope_index("ui.cursor.primary.insert"),
364+ Mode::Select => theme.find_scope_index("ui.cursor.primary.select"),
365+ Mode::Normal => theme.find_scope_index("ui.cursor.primary.normal"),
366+ }
367+ .unwrap_or(base_primary_cursor_scope);
362368
363369 let mut spans: Vec<(usize, std::ops::Range<usize>)> = Vec::new();
364370 for (i, range) in selection.iter().enumerate() {