From d1c8a74771b241ee0824853bd5e8229cb0ab4187 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Mon, 14 Jun 2021 19:31:17 +0530 Subject: Add theme key for selected line number Adds `ui.linenr.selected` which controls highlight of linu numbes which have cursors on. - Fallback to linenr if linenr.selected is missing - Update docs and themes - Add TODOs for themes with temporary linenr.selected --- helix-term/src/ui/editor.rs | 81 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 35 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 95587b4c..63b3e277 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -232,7 +232,45 @@ impl EditorView { } } - // render selections + // render gutters + + let linenr: Style = theme.get("ui.linenr"); + let warning: Style = theme.get("warning"); + let error: Style = theme.get("error"); + let info: Style = theme.get("info"); + let hint: Style = theme.get("hint"); + + for (i, line) in (view.first_line..last_line).enumerate() { + use helix_core::diagnostic::Severity; + if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) { + surface.set_stringn( + viewport.x - OFFSET, + viewport.y + i as u16, + "●", + 1, + match diagnostic.severity { + Some(Severity::Error) => error, + Some(Severity::Warning) | None => warning, + Some(Severity::Info) => info, + Some(Severity::Hint) => hint, + }, + ); + } + + // line numbers having selections are rendered differently + surface.set_stringn( + viewport.x + 1 - OFFSET, + viewport.y + i as u16, + format!("{:>5}", line + 1), + 5, + linenr, + ); + } + + // render selections and selected linenr(s) + let linenr_select: Style = theme + .try_get("ui.linenr.selected") + .unwrap_or_else(|| theme.get("ui.linenr")); if is_focused { let screen = { @@ -329,6 +367,13 @@ impl EditorView { ), cursor_style, ); + surface.set_stringn( + viewport.x + 1 - OFFSET, + viewport.y + head.row as u16, + format!("{:>5}", view.first_line + head.row + 1), + 5, + linenr_select, + ); // TODO: set cursor position for IME if let Some(syntax) = doc.syntax() { use helix_core::match_brackets; @@ -357,40 +402,6 @@ impl EditorView { } } } - - // render gutters - - let style: Style = theme.get("ui.linenr"); - let warning: Style = theme.get("warning"); - let error: Style = theme.get("error"); - let info: Style = theme.get("info"); - let hint: Style = theme.get("hint"); - - for (i, line) in (view.first_line..last_line).enumerate() { - use helix_core::diagnostic::Severity; - if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) { - surface.set_stringn( - viewport.x - OFFSET, - viewport.y + i as u16, - "●", - 1, - match diagnostic.severity { - Some(Severity::Error) => error, - Some(Severity::Warning) | None => warning, - Some(Severity::Info) => info, - Some(Severity::Hint) => hint, - }, - ); - } - - surface.set_stringn( - viewport.x + 1 - OFFSET, - viewport.y + i as u16, - format!("{:>5}", line + 1), - 5, - style, - ); - } } pub fn render_diagnostics( -- cgit v1.2.3-70-g09d2