This commit is contained in:
Vivek Kethineni 2024-11-22 08:36:43 -03:00 committed by GitHub
commit c8598e15d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -510,6 +510,7 @@ pub fn doc(&self) -> &str {
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",
@ -5357,6 +5358,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| {