From f157a918a334b6f84730ffa358d766562f81727b Mon Sep 17 00:00:00 2001 From: Rock Boynton Date: Thu, 15 May 2025 14:53:02 +0200 Subject: [PATCH] Show the primary selection index on statusline (#12326) Co-authored-by: Rock Boynton Co-authored-by: Michael Davis --- book/src/editor.md | 2 +- helix-term/src/ui/statusline.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/book/src/editor.md b/book/src/editor.md index b79792058..c2a7af764 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -138,7 +138,7 @@ The following statusline elements can be configured: | `file-type` | The type of the opened file | | `diagnostics` | The number of warnings and/or errors | | `workspace-diagnostics` | The number of warnings and/or errors on workspace | -| `selections` | The number of active selections | +| `selections` | The primary selection index out of the number of active selections | | `primary-selection-length` | The number of characters currently in primary selection | | `position` | The cursor position | | `position-percentage` | The cursor position as a percentage of the total number of lines | diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 4d4b9f2fe..df23123c5 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -332,10 +332,15 @@ fn render_selections<'a, F>(context: &mut RenderContext<'a>, write: F) where F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, { - let count = context.doc.selection(context.view.id).len(); + let selection = context.doc.selection(context.view.id); + let count = selection.len(); write( context, - format!(" {} sel{} ", count, if count == 1 { "" } else { "s" }).into(), + if count == 1 { + " 1 sel ".into() + } else { + format!(" {}/{count} sels ", selection.primary_index() + 1).into() + }, ); }