on master help sign in
Fix recursive macro crash and empty macro lockout (#2902)
commit030de46e6b9568f27fd89b1543d978b21da7464e authorPabloMansanet <pablomansanet@gmail.com> dateTue 28 Jun 2022, 21:30 (4 years ago) parentac1d8fa
1 file changed+8−4
helix-term/src/commands.rs+8−4
helix-term/src/commands.rs+8−4
@@ -4655,8 +4655,6 @@ fn replay_macro(cx: &mut Context) {
46554655 return;
46564656 }
46574657
4658− cx.editor.macro_replaying.push(reg);
4659−
46604658 let keys: Vec<KeyEvent> = if let Some([keys_str]) = cx.editor.registers.read(reg) {
46614659 match helix_view::input::parse_macro(keys_str) {
46624660 Ok(keys) => keys,
@@ -4670,6 +4668,10 @@ fn replay_macro(cx: &mut Context) {
46704668 return;
46714669 };
46724670
4671+ // Once the macro has been fully validated, it's marked as being under replay
4672+ // to ensure we don't fall into infinite recursion.
4673+ cx.editor.macro_replaying.push(reg);
4674+
46734675 let count = cx.count();
46744676 cx.callback = Some(Box::new(move |compositor, cx| {
46754677 for _ in 0..count {
@@ -4677,7 +4679,9 @@ fn replay_macro(cx: &mut Context) {
46774679 compositor.handle_event(crossterm::event::Event::Key(key.into()), cx);
46784680 }
46794681 }
4682+ // The macro under replay is cleared at the end of the callback, not in the
4683+ // macro replay context, or it will not correctly protect the user from
4684+ // replaying recursively.
4685+ cx.editor.macro_replaying.pop();
46804686 }));
4681−
4682− cx.editor.macro_replaying.pop();
46834687}