diff options
author | radical3dd | 2021-10-21 00:44:53 +0000 |
---|---|---|
committer | GitHub | 2021-10-21 00:44:53 +0000 |
commit | b1ebd7a07e55f8ff5b8ef9fcbf09940a9f4a4f39 (patch) | |
tree | 99274f39890250165b61a2b50b5a134be4c6159c | |
parent | e9b23c29d8e8bca1d4140d02350bdae824a651b0 (diff) |
Replace current selection with all yanked values. (#882)
-rw-r--r-- | helix-term/src/commands.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 2811f293..9f54292d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3782,11 +3782,21 @@ fn replace_with_yanked(cx: &mut Context) { let registers = &mut cx.editor.registers; if let Some(values) = registers.read(reg_name) { - if let Some(yank) = values.first() { + if !values.is_empty() { + let repeat = std::iter::repeat( + values + .last() + .map(|value| Tendril::from_slice(value)) + .unwrap(), + ); + let mut values = values + .iter() + .map(|value| Tendril::from_slice(value)) + .chain(repeat); let selection = doc.selection(view.id); let transaction = Transaction::change_by_selection(doc.text(), selection, |range| { if !range.is_empty() { - (range.from(), range.to(), Some(yank.as_str().into())) + (range.from(), range.to(), Some(values.next().unwrap())) } else { (range.from(), range.to(), None) } |