From 3dd2196e4f42b23fd30b4e028b96d5b1862603d6 Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Tue, 26 Jul 2022 08:05:12 +0200 Subject: [PATCH] add position-percentage as a statusline indicator (#3168) * added position-pct as a statusline indicator * removed unnecessary mutable reference * pct -> percent * percent -> percentage --- book/src/configuration.md | 1 + helix-term/src/ui/statusline.rs | 31 ++++++++++++++++++++++++------- helix-view/src/editor.rs | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index c7334af4f..5372b9f03 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -78,6 +78,7 @@ ### `[editor.statusline]` Section | `diagnostics` | The number of warnings and/or errors | | `selections` | The number of active selections | | `position` | The cursor position | +| `position-percentage` | The cursor position as a percentage of the total number of lines | | `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) | ### `[editor.lsp]` Section diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index e9e478bff..df6d48000 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -1,4 +1,4 @@ -use helix_core::{coords_at_pos, encoding}; +use helix_core::{coords_at_pos, encoding, Position}; use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, graphics::Rect, @@ -143,6 +143,7 @@ fn get_render_function(element_id: StatusLineElementID) -> impl Fn(&mut Rende helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics, helix_view::editor::StatusLineElement::Selections => render_selections, helix_view::editor::StatusLineElement::Position => render_position, + helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage, helix_view::editor::StatusLineElement::Spacer => render_spacer, } } @@ -251,19 +252,22 @@ fn render_selections(context: &mut RenderContext, write: F) ); } -fn render_position(context: &mut RenderContext, write: F) -where - F: Fn(&mut RenderContext, String, Option