Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursive macro crash and empty macro lockout #2902

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4655,8 +4655,6 @@ fn replay_macro(cx: &mut Context) {
return;
}

cx.editor.macro_replaying.push(reg);

let keys: Vec<KeyEvent> = if let Some([keys_str]) = cx.editor.registers.read(reg) {
match helix_view::input::parse_macro(keys_str) {
Ok(keys) => keys,
Expand All @@ -4670,14 +4668,20 @@ fn replay_macro(cx: &mut Context) {
return;
};

// Once the macro has been fully validated, it's marked as being under replay
// to ensure we don't fall into infinite recursion.
cx.editor.macro_replaying.push(reg);

let count = cx.count();
cx.callback = Some(Box::new(move |compositor, cx| {
for _ in 0..count {
for &key in keys.iter() {
compositor.handle_event(crossterm::event::Event::Key(key.into()), cx);
}
}
// The macro under replay is cleared at the end of the callback, not in the
// macro replay context, or it will not correctly protect the user from
// replaying recursively.
cx.editor.macro_replaying.pop();
}));

cx.editor.macro_replaying.pop();
}