changeset 6796:44b81c8fb513

Show the primary selection index on statusline (#12326) Co-authored-by: Rock Boynton <[email protected]> Co-authored-by: Michael Davis <[email protected]>
author Rock Boynton <rock.boynton@yahoo.com>
date Thu, 15 May 2025 14:53:02 +0200
parents 32d8f329f44c
children def567db4436
files book/src/editor.md helix-term/src/ui/statusline.rs
diffstat 2 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/book/src/editor.md	Thu May 15 08:24:33 2025 -0400
+++ b/book/src/editor.md	Thu May 15 14:53:02 2025 +0200
@@ -138,7 +138,7 @@
 | `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 |
--- a/helix-term/src/ui/statusline.rs	Thu May 15 08:24:33 2025 -0400
+++ b/helix-term/src/ui/statusline.rs	Thu May 15 14:53:02 2025 +0200
@@ -332,10 +332,15 @@
 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()
+        },
     );
 }