added command to copy contents of registers between each other

pull/9717/head
Vivek Kethineni 9 months ago
parent 59369d99e2
commit ca3574be35

@ -440,6 +440,7 @@ impl MappableCommand {
wclose, "Close window", wclose, "Close window",
wonly, "Close windows except current", wonly, "Close windows except current",
select_register, "Select register", select_register, "Select register",
copy_between_registers, "Copy contents of selected register to another",
insert_register, "Insert register", insert_register, "Insert register",
align_view_middle, "Align view middle", align_view_middle, "Align view middle",
align_view_top, "Align view top", align_view_top, "Align view top",
@ -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) { fn insert_register(cx: &mut Context) {
cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers)); cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers));
cx.on_next_key(move |cx, event| { cx.on_next_key(move |cx, event| {

Loading…
Cancel
Save