Skip to content

Commit

Permalink
added command to copy contents of registers between each other
Browse files Browse the repository at this point in the history
  • Loading branch information
uek-1 committed Feb 24, 2024
1 parent 59369d9 commit ca3574b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ impl MappableCommand {
wclose, "Close window",
wonly, "Close windows except current",
select_register, "Select register",
copy_between_registers, "Copy contents of selected register to another",
insert_register, "Insert register",
align_view_middle, "Align view middle",
align_view_top, "Align view top",
Expand Down Expand Up @@ -4805,6 +4806,24 @@ fn select_register(cx: &mut Context) {
})
}

fn copy_between_registers(cx: &mut Context) {
// Copy from selected register to the register of the next keypress
let Some(values) = cx.editor.registers.read(cx.register.unwrap_or('"'), cx.editor) else {
return;
};

let values: Vec<String> = values.map(|value| value.to_string()).collect();

cx.on_next_key(move |cx, event| {
if let Some(ch) = event.char() {
if let Err(err) = cx.editor.registers.write(ch, values) {
cx.editor.set_error(err.to_string());
return;
}
}
})
}

fn insert_register(cx: &mut Context) {
cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers));
cx.on_next_key(move |cx, event| {
Expand Down

0 comments on commit ca3574b

Please sign in to comment.