Improve macro error handling

imgbot
Ivan Tham 3 years ago committed by Blaž Hrastnik
parent c7a59e24e6
commit 5326a05117

@ -6031,23 +6031,17 @@ fn record_macro(cx: &mut Context) {
fn play_macro(cx: &mut Context) { fn play_macro(cx: &mut Context) {
let reg = cx.register.unwrap_or('@'); let reg = cx.register.unwrap_or('@');
let keys = match cx let keys: Vec<KeyEvent> = if let Some([keys]) = cx.editor.registers.read(reg) {
.editor match keys.split_whitespace().map(str::parse).collect() {
.registers
.get(reg)
.and_then(|reg| reg.read().get(0))
.context("Register empty")
.and_then(|s| {
s.split_whitespace()
.map(str::parse::<KeyEvent>)
.collect::<Result<Vec<_>, _>>()
.context("Failed to parse macro")
}) {
Ok(keys) => keys, Ok(keys) => keys,
Err(e) => { Err(err) => {
cx.editor.set_error(format!("{}", e)); cx.editor.set_error(format!("Invalid macro: {}", err));
return; return;
} }
}
} else {
cx.editor.set_error(format!("Register [{}] empty", reg));
return;
}; };
let count = cx.count(); let count = cx.count();

Loading…
Cancel
Save