Show the primary selection index on statusline

Have the status line show the number of the current selection out of
the total in the file.

Right now, the `# sels` shows how many selections you have in the current
buffer, but this shows the (1-based) index at which which one your
primary cursor is on in the current buffer, i.e. `3/6 sels`, then if you
press `)`, it would say `4/6` sels etc.

This is very helpful when multiple selections are spread out beyond
a single view to orient oneself with the current selections.
pull/12326/head
Rock Boynton 2024-12-23 14:59:46 -08:00
parent e4ef096945
commit 612f48f3cd
2 changed files with 9 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

@ -347,10 +347,16 @@ fn render_selections<F>(context: &mut RenderContext, write: F)
where where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy, F: Fn(&mut RenderContext, String, Option<Style>) + 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" }), format!(
"{}/{} sel{} ",
selection.primary_index() + 1,
count,
if count == 1 { "" } else { "s" }
),
None, None,
); );
} }