From a2b22ec15207926acf9bbf6617492925a6e50d27 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 6 Dec 2021 12:48:25 +0900 Subject: Use binary_search when looking up diagnostics They're sorted by range so they should also be sorted by line --- helix-view/src/gutter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'helix-view/src/gutter.rs') diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index 86773c1d..4c0edd90 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -22,7 +22,7 @@ pub fn diagnostic<'doc>( Box::new(move |line: usize, _selected: bool, out: &mut String| { use helix_core::diagnostic::Severity; - if let Some(diagnostic) = diagnostics.iter().find(|d| d.line == line) { + if let Some(diagnostic) = diagnostics.binary_search_by_key(&line, |d| d.line) { write!(out, "●").unwrap(); return Some(match diagnostic.severity { Some(Severity::Error) => error, -- cgit v1.2.3-70-g09d2 From 35ac8154095b7eb853e0bc9bfca0879ec5b60be9 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 6 Dec 2021 12:50:28 +0900 Subject: Fix compilation nix-direnv issues still mess with my shell.. --- helix-view/src/gutter.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'helix-view/src/gutter.rs') diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index 4c0edd90..af016c56 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -22,7 +22,8 @@ pub fn diagnostic<'doc>( Box::new(move |line: usize, _selected: bool, out: &mut String| { use helix_core::diagnostic::Severity; - if let Some(diagnostic) = diagnostics.binary_search_by_key(&line, |d| d.line) { + if let Ok(index) = diagnostics.binary_search_by_key(&line, |d| d.line) { + let diagnostic = &diagnostics[index]; write!(out, "●").unwrap(); return Some(match diagnostic.severity { Some(Severity::Error) => error, -- cgit v1.2.3-70-g09d2 From 333c2949c2b036f8aafa77be2286eb3c135ea269 Mon Sep 17 00:00:00 2001 From: Andrew Neth Date: Tue, 25 Jan 2022 09:18:01 -0600 Subject: feat(helix-view): dynamic line numbers (#1522) * feat(helix-view): dynamic line numbers * docs: describe editor.line-number in more detail * Make dynamic numbers the default behavior of `relative`--- book/src/configuration.md | 2 +- helix-view/src/editor.rs | 4 +++- helix-view/src/gutter.rs | 24 +++++++++++++----------- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'helix-view/src/gutter.rs') diff --git a/book/src/configuration.md b/book/src/configuration.md index 7f2a4acf..8048f548 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -34,7 +34,7 @@ hidden = false | `middle-click-paste` | Middle click paste support. | `true` | | `scroll-lines` | Number of lines to scroll per scroll wheel step. | `3` | | `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`
Windows: `["cmd", "/C"]` | -| `line-number` | Line number display (`absolute`, `relative`) | `absolute` | +| `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers. | `absolute` | | `smart-case` | Enable smart case regex searching (case insensitive unless pattern contains upper case characters) | `true` | | `auto-pairs` | Enable automatic insertion of pairs to parenthese, brackets, etc. | `true` | | `auto-completion` | Enable automatic pop up of auto-completion. | `true` | diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 82ef0cdc..aa2df6f7 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -170,7 +170,9 @@ impl Default for CursorShapeConfig { pub enum LineNumber { /// Show absolute line number Absolute, - /// Show relative line number to the primary cursor + + /// If focused and in normal/select mode, show relative line number to the primary cursor. + /// If unfocused or in insert mode, show absolute line number. Relative, } diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index af016c56..113da642 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -58,29 +58,31 @@ pub fn line_number<'doc>( .char_to_line(doc.selection(view.id).primary().cursor(text)); let config = config.line_number; + let mode = doc.mode; Box::new(move |line: usize, selected: bool, out: &mut String| { if line == last_line && !draw_last { write!(out, "{:>1$}", '~', width).unwrap(); Some(linenr) } else { - use crate::editor::LineNumber; - let line = match config { - LineNumber::Absolute => line + 1, - LineNumber::Relative => { - if current_line == line { - line + 1 - } else { - abs_diff(current_line, line) - } - } + use crate::{document::Mode, editor::LineNumber}; + + let relative = config == LineNumber::Relative + && mode != Mode::Insert + && is_focused + && current_line != line; + + let display_num = if relative { + abs_diff(current_line, line) + } else { + line + 1 }; let style = if selected && is_focused { linenr_select } else { linenr }; - write!(out, "{:>1$}", line, width).unwrap(); + write!(out, "{:>1$}", display_num, width).unwrap(); Some(style) } }) -- cgit v1.2.3-70-g09d2