@@ -17,6 +17,7 @@ use helix_core::{
1717};
1818use helix_view::{
1919 document::Mode,
20+ editor::LineNumber,
2021 graphics::{CursorKind, Modifier, Rect, Style},
2122 info::Info,
2223 input::KeyEvent,
@@ -71,6 +72,7 @@ impl EditorView {
7172 theme: &Theme,
7273 is_focused: bool,
7374 loader: &syntax::Loader,
75+ config: &helix_view::editor::Config,
7476 ) {
7577 let area = Rect::new(
7678 view.area.x + GUTTER_OFFSET,
@@ -93,7 +95,7 @@ impl EditorView {
9395 };
9496
9597 Self::render_text_highlights(doc, offset, area, surface, theme, highlights);
96− Self::render_gutter(doc, view, area, surface, theme);
98+ Self::render_gutter(doc, view, area, surface, theme, config);
9799
98100 if is_focused {
99101 Self::render_focused_view_elements(view, doc, area, theme, surface);
@@ -459,6 +461,7 @@ impl EditorView {
459461 viewport: Rect,
460462 surface: &mut Surface,
461463 theme: &Theme,
464+ config: &helix_view::editor::Config,
462465 ) {
463466 let text = doc.text().slice(..);
464467 let last_line = view.last_line(doc);
@@ -473,6 +476,9 @@ impl EditorView {
473476 // document or not. We only draw it if it's not an empty line.
474477 let draw_last = text.line_to_byte(last_line) < text.len_bytes();
475478
479+ let current_line = doc
480+ .text()
481+ .char_to_line(doc.selection(view.id).primary().anchor);
476482 for (i, line) in (view.first_line..(last_line + 1)).enumerate() {
477483 use helix_core::diagnostic::Severity;
478484 if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
@@ -495,7 +501,13 @@ impl EditorView {
495501 let line_number_text = if line == last_line && !draw_last {
496502 " ~".into()
497503 } else {
498− format!("{:>5}", line + 1)
504+ match config.line_number {
505+ LineNumber::Absolute => format!("{:>5}", line + 1),
506+ LineNumber::Relative => {
507+ let relative_line = abs_diff(current_line, line);
508+ format!("{:>5}", relative_line)
509+ }
510+ }
499511 };
500512 surface.set_stringn(
501513 viewport.x + 1 - GUTTER_OFFSET,
@@ -1042,6 +1054,7 @@ impl Component for EditorView {
10421054 &cx.editor.theme,
10431055 is_focused,
10441056 loader,
1057+ &cx.editor.config,
10451058 );
10461059 }
10471060
@@ -1115,3 +1128,12 @@ fn canonicalize_key(key: &mut KeyEvent) {
11151128 key.modifiers.remove(KeyModifiers::SHIFT)
11161129 }
11171130}
1131+
1132+#[inline]
1133+fn abs_diff(a: usize, b: usize) -> usize {
1134+ if a > b {
1135+ a - b
1136+ } else {
1137+ b - a
1138+ }
1139+}