diff --git a/core/editor/editor.cpp b/core/editor/editor.cpp index 8e7878b..f43e0f7 100644 --- a/core/editor/editor.cpp +++ b/core/editor/editor.cpp @@ -144,6 +144,7 @@ i32 EditorGutterWidth(Editor *ed, const Panel *panel) { u64 EditorLineNumberLabel(const Editor *ed, const View *view, const Buffer *buffer, u64 line) { if (ed && ed->line_number_mode == LineNumberMode::Relative) { u64 cursor_line = ViewCursorLine(view, buffer); + if (line == cursor_line) return line + 1; return (line > cursor_line) ? line - cursor_line : cursor_line - line; } return line + 1; // buffer lines are 0-based; the display is not diff --git a/core/editor/editor.h b/core/editor/editor.h index c58a5fd..352fd63 100644 --- a/core/editor/editor.h +++ b/core/editor/editor.h @@ -16,8 +16,8 @@ inline constexpr u64 kMaxRecordedChords = 128; // What the gutter counts. Relative shows each line's distance from the cursor, -// with 0 on the cursor's own line, which is what makes a jump count something -// you read rather than work out. +// with the absolute 1-based number on the cursor's own line (vim's number + +// relativenumber), so a jump count is something you read rather than work out. // // There is no config file, so this is a source-level setting: change // kLineNumberModeDefault and rebuild. :number, :relativenumber and :nonumber @@ -220,8 +220,8 @@ void EditorSetScreen(Editor *ed, RectS32 screen); // plus one blank column separating the numbers from the text. [[nodiscard]] i32 EditorGutterWidth(Editor *ed, const Panel *panel); -// The number `line` displays: its distance from the cursor when relative (0 on -// the cursor's own line), otherwise the 1-based line number. +// The number `line` displays: its distance from the cursor when relative, or +// the 1-based line number on the cursor's own line / in absolute mode. [[nodiscard]] u64 EditorLineNumberLabel(const Editor *ed, const View *view, const Buffer *buffer, u64 line); diff --git a/docs/rendering.md b/docs/rendering.md index 4c7947f..d461e8f 100644 --- a/docs/rendering.md +++ b/docs/rendering.md @@ -4,9 +4,10 @@ Fonts are chosen at runtime. Colours are compiled in. ## Line numbers -The gutter shows each line's distance from the cursor, with `0` on the cursor's -own line — vim's `relativenumber`. `:number` switches to absolute numbers, -`:relativenumber` back, and `:nonumber` hides the gutter entirely. +The gutter shows each line's distance from the cursor, with the absolute +1-based number on the cursor's own line — vim's `number` + `relativenumber`. +`:number` switches to absolute numbers, `:relativenumber` back, and +`:nonumber` hides the gutter entirely. To change what it starts as, edit one constant in `core/editor/editor.h`: diff --git a/tests/test_vim.cpp b/tests/test_vim.cpp index c97337b..bbb22a4 100644 --- a/tests/test_vim.cpp +++ b/tests/test_vim.cpp @@ -1598,8 +1598,8 @@ TEST(line_numbers_relative_labels_count_from_the_cursor) { Type(&f, "2j"); CHECK_EQ(CursorLine(&f), 2); - // Zero on the cursor's own line, distances either side of it. - CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 2), 0); + // Absolute number on the cursor's own line, distances either side of it. + CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 2), 3); CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 1), 1); CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 0), 2); CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 3), 1); @@ -1608,7 +1608,7 @@ TEST(line_numbers_relative_labels_count_from_the_cursor) { // They follow the cursor rather than being computed once. Type(&f, "j"); CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 2), 1); - CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 3), 0); + CHECK_EQ(EditorLineNumberLabel(&f.ed, view, buffer, 3), 4); Destroy(&f); }