@@ -17,6 +17,7 @@ use helix_core::{
18use helix_view::{
18use helix_view::{
19 document::Mode,
19 document::Mode,
20 graphics::{CursorKind, Modifier, Rect, Style},
21 graphics::{CursorKind, Modifier, Rect, Style},
21 info::Info,
22 info::Info,
22 input::KeyEvent,
23 input::KeyEvent,
@@ -71,6 +72,7 @@ impl EditorView {
71 theme: &Theme,
72 theme: &Theme,
72 is_focused: bool,
73 is_focused: bool,
73 loader: &syntax::Loader,
74 loader: &syntax::Loader,
75+ config: &helix_view::editor::Config,
75 let area = Rect::new(
77 let area = Rect::new(
76 view.area.x + GUTTER_OFFSET,
78 view.area.x + GUTTER_OFFSET,
@@ -93,7 +95,7 @@ impl EditorView {
95 Self::render_text_highlights(doc, offset, area, surface, theme, highlights);
97 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);
98 if is_focused {
100 if is_focused {
99 Self::render_focused_view_elements(view, doc, area, theme, surface);
101 Self::render_focused_view_elements(view, doc, area, theme, surface);
@@ -459,6 +461,7 @@ impl EditorView {
459 viewport: Rect,
461 viewport: Rect,
460 surface: &mut Surface,
462 surface: &mut Surface,
461 theme: &Theme,
463 theme: &Theme,
464+ config: &helix_view::editor::Config,
463 let text = doc.text().slice(..);
466 let text = doc.text().slice(..);
464 let last_line = view.last_line(doc);
467 let last_line = view.last_line(doc);
@@ -473,6 +476,9 @@ impl EditorView {
473 // document or not. We only draw it if it's not an empty line.
476 // document or not. We only draw it if it's not an empty line.
474 let draw_last = text.line_to_byte(last_line) < text.len_bytes();
477 let draw_last = text.line_to_byte(last_line) < text.len_bytes();
479+ let current_line = doc
481+ .char_to_line(doc.selection(view.id).primary().anchor);
476 for (i, line) in (view.first_line..(last_line + 1)).enumerate() {
482 for (i, line) in (view.first_line..(last_line + 1)).enumerate() {
477 use helix_core::diagnostic::Severity;
483 use helix_core::diagnostic::Severity;
478 if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
484 if let Some(diagnostic) = doc.diagnostics().iter().find(|d| d.line == line) {
@@ -495,7 +501,13 @@ impl EditorView {
495 let line_number_text = if line == last_line && !draw_last {
501 let line_number_text = if line == last_line && !draw_last {
496 " ~".into()
502 " ~".into()
504+ match config.line_number {
498− format!("{:>5}", line + 1)
505+ LineNumber::Absolute => format!("{:>5}", line + 1),
506+ LineNumber::Relative => {
507+ let relative_line = abs_diff(current_line, line);
508+ format!("{:>5}", relative_line)
500 surface.set_stringn(
512 surface.set_stringn(
501 viewport.x + 1 - GUTTER_OFFSET,
513 viewport.x + 1 - GUTTER_OFFSET,
@@ -1042,6 +1054,7 @@ impl Component for EditorView {
1042 &cx.editor.theme,
1054 &cx.editor.theme,
1043 is_focused,
1055 is_focused,
@@ -1115,3 +1128,12 @@ fn canonicalize_key(key: &mut KeyEvent) {
1115 key.modifiers.remove(KeyModifiers::SHIFT)
1128 key.modifiers.remove(KeyModifiers::SHIFT)
1133+fn abs_diff(a: usize, b: usize) -> usize {