Undo after stopping a recording on an unfocused track deletes the track and skips an undo step
Bug description
After stopping a recording while the track is unfocused (or after unfocusing and refocusing the track), pressing Undo deletes the entire track instead of undoing the recorded take. Pressing Undo again restores the track, but the undo history has skipped a step -> effectively 3 -> track deleted -> 1 instead of 3 -> 2 -> 1.
Steps to reproduce
- Start recording on a track.
- While recording, unfocus the track/press anywhere else on the track or other track (or unfocus and then refocus it).
- Stop the recording while the track is unfocused.
- Press Undo (Ctrl+Z or Edit > Undo).
- Observe that the whole track is deleted instead of undoing the recording.
- Press Undo again.
- Observe the track is restored, but a previous undo step has been skipped.
Expected behavior
After stopping a recording, Undo removes the recorded audio (3 -> 2). It should never delete the track itself, and no undo step should be skipped.
Actual behavior
Undo deletes the track outright. A second Undo restores the track but skips the previous history step, landing on 1 instead of 2.
Audacity Version
Audacity 4.0.0
Operating system
Windows
Additional context
Reproduced with the track losing/regaining focus between starting the recording and stopping it. This may be a focus-handling issue in how the undo stack is built during recording.
Source: audacity/audacity