From ac1e98d088dcb05bfb72d39bc33394163b8303ba Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sun, 20 Jun 2021 21:47:35 +0200 Subject: [PATCH] Add ability to theme cursor --- helix-term/src/ui/editor.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 550ff181e..43f1069d7 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -281,9 +281,17 @@ impl EditorView { let end = text.line_to_char(last_line + 1); Range::new(start, end) }; - let cursor_style = Style::default() - // .bg(Color::Rgb(255, 255, 255)) - .add_modifier(Modifier::REVERSED); + let scope = match doc.mode() { + Mode::Insert => "ui.cursor.insert", + Mode::Select => "ui.cursor.select", + Mode::Normal => "ui.cursor", + }; + let cursor_style = theme.try_get(scope).unwrap_or_else(|| { + theme + //if cursor.insert or cursor.select was not present try to default to cursor + .try_get("ui.cursor") + .unwrap_or_else(|| Style::default().add_modifier(Modifier::REVERSED)) + }); let selection_style = theme.get("ui.selection"); @@ -388,9 +396,12 @@ impl EditorView { if (pos.col as u16) < viewport.width + view.first_col as u16 && pos.col >= view.first_col { - let style = Style::default() - .add_modifier(Modifier::REVERSED) - .add_modifier(Modifier::DIM); + let style = + theme.try_get("ui.cursor.match").unwrap_or_else(|| { + Style::default() + .add_modifier(Modifier::REVERSED) + .add_modifier(Modifier::DIM) + }); surface .get_mut(