Show the primary selection index on statusline (#12326)

Co-authored-by: Rock Boynton <rboynton@anduril.com>
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
pull/13540/head
Rock Boynton 2025-05-15 14:53:02 +02:00 committed by GitHub
parent a7c3a43069
commit f157a918a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -138,7 +138,7 @@ The following statusline elements can be configured:
| `file-type` | The type of the opened file | | `file-type` | The type of the opened file |
| `diagnostics` | The number of warnings and/or errors | | `diagnostics` | The number of warnings and/or errors |
| `workspace-diagnostics` | The number of warnings and/or errors on workspace | | `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 | | `primary-selection-length` | The number of characters currently in primary selection |
| `position` | The cursor position | | `position` | The cursor position |
| `position-percentage` | The cursor position as a percentage of the total number of lines | | `position-percentage` | The cursor position as a percentage of the total number of lines |

View File

@ -332,10 +332,15 @@ fn render_selections<'a, F>(context: &mut RenderContext<'a>, write: F)
where where
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, 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( write(
context, 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()
},
); );
} }