diff --git a/book/src/editor.md b/book/src/editor.md index 667a7147c..05f5f3ded 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -55,6 +55,7 @@ | `insert-final-newline` | Whether to automatically insert a trailing line-ending on write if missing | `true` | | `trim-final-newlines` | Whether to automatically remove line-endings after the final one on write | `false` | | `trim-trailing-whitespace` | Whether to automatically remove whitespace preceding line endings on write | `false` | +| `pad_selection_index_register` | Whether to align selection indices register with zero padding | `false` | | `popup-border` | Draw border around `popup`, `menu`, `all`, or `none` | `none` | | `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid` | `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"` diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index cb9586e79..273e759d9 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -354,6 +354,8 @@ pub struct Config { pub trim_trailing_whitespace: bool, /// Enables smart tab pub smart_tab: Option, + /// Enables padding selection indecis register + pub pad_selection_index_register: bool, /// Draw border around popups. pub popup_border: PopupBorderConfig, /// Which indent heuristic to use when a new line is inserted @@ -1024,6 +1026,7 @@ impl Default for Config { trim_final_newlines: false, trim_trailing_whitespace: false, smart_tab: Some(SmartTabConfig::default()), + pad_selection_index_register: false, popup_border: PopupBorderConfig::None, indent_heuristic: IndentationHeuristic::default(), jump_label_alphabet: ('a'..='z').collect(), diff --git a/helix-view/src/register.rs b/helix-view/src/register.rs index b2bb53ac2..af34588a6 100644 --- a/helix-view/src/register.rs +++ b/helix-view/src/register.rs @@ -46,11 +46,16 @@ impl Registers { '#' => { let (view, doc) = current_ref!(editor); let selections = doc.selection(view.id).len(); + let number_of_digits = if editor.config().pad_selection_index_register { + selections.ilog10() as usize + 1 + } else { + 0 + }; // ExactSizeIterator is implemented for Range but // not RangeInclusive. - Some(RegisterValues::new( - (0..selections).map(|i| (i + 1).to_string().into()), - )) + Some(RegisterValues::new((0..selections).map(move |i| { + format!("{:0width$}", i + 1, width = number_of_digits).into() + }))) } '.' => { let (view, doc) = current_ref!(editor);