Skip to content

Commit

Permalink
Do not record keys pressed by macros while recording a macro (#12733)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Davis <[email protected]>
  • Loading branch information
renshyle and the-mikedavis authored Jan 31, 2025
1 parent 6906164 commit 80dbe03
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ impl Compositor {
}

pub fn handle_event(&mut self, event: &Event, cx: &mut Context) -> bool {
// If it is a key event and a macro is being recorded, push the key event to the recording.
// If it is a key event, a macro is being recorded, and a macro isn't being replayed,
// push the key event to the recording.
if let (Event::Key(key), Some((_, keys))) = (event, &mut cx.editor.macro_recording) {
keys.push(*key);
if cx.editor.macro_replaying.is_empty() {
keys.push(*key);
}
}

let mut callbacks = Vec::new();
Expand Down
27 changes: 27 additions & 0 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,30 @@ fn foo() {

Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn macro_play_within_macro_record() -> anyhow::Result<()> {
// <https://github.com/helix-editor/helix/issues/12697>
//
// * `"aQihello<esc>Q` record a macro to register 'a' which inserts "hello"
// * `Q"aq<space>world<esc>Q` record a macro to the default macro register which plays the
// macro in register 'a' and then inserts " world"
// * `%d` clear the buffer
// * `q` replay the macro in the default macro register
// * `i<ret>` add a newline at the end
//
// The inner macro in register 'a' should replay within the outer macro exactly once to insert
// "hello world".
test((
indoc! {"\
#[|]#
"},
r#""aQihello<esc>QQ"aqi<space>world<esc>Q%dqi<ret>"#,
indoc! {"\
hello world
#[|]#"},
))
.await?;

Ok(())
}

0 comments on commit 80dbe03

Please sign in to comment.