Bugzilla – Bug 2499
Macros: applying Macro to project always sets first track as focus
Last modified: 2020-07-04 10:54:54 UTC
Applying a macro to the project sets the first track as the focus - it was spotted by someone on the forums. After applying commands such as delete, one would expect the focus to be unchanged. After applying effects, one would currently expect to the focus to be the first selected track. This is inconvenient for keyboard users who then probably have to move back to the track which they were working on. This is a regression on 2.3.3. The cause of the problem is in: bool MacroCommands::ApplyMacro( const MacroCommandsCatalog &catalog, const wxString & filename) Specifically, the lines: auto cleanup2 = finally([&] { if (!res) { if (proj) { // Macro failed or was cancelled; revert to the previous state ProjectHistory::Get(*proj).RollbackState(); } } }); The boolean res is always false, RollbackState() is called, which eventually causes TrackPanel::OnUndoReset() to be called, which sets the first track to be the focus.
I had assumed this behaviour was intended. On Linux with Audacity 2.3.3, track focus is lost altogether after running a Macro, so the current behaviour is an improvement, though I think returning focus to the first audio track unexpected. I would have expected focus to return to wherever focus was prior to running the Macro.
(In reply to Steve Daulton from comment #1) >I would have expected focus to return to wherever focus was prior to >running the Macro. Not necessarily as there are several Macro commands for changing the focused track. Accordingly, I think: a) If focussed track is changed in the Macro it should be left where it was last changed to. b) If focussed track is not changed in the Macro it should be left where it was before the Macro was run.
Fixed with commits: https://github.com/audacity/audacity/commit/d9663035586a5cf60f4b7e5701c1e98356759691 https://github.com/audacity/audacity/commit/51b3b0f19a7f7699f029f33b43a9c7e62c1179b4 (Alas, I forgot to squash before committing.) Notes: 1. On the basis of comments made by Steve, this bug may have accidentally fixed a bug on Linux where the track panel does not regain focus after executing a macro. If this is the case, then this fix will reintroduce that bug, which should be logged as a separate bug. 2. This fix also fixes a bug when a command in a macro is cancelled. Prior to the fix, if a macro contained a number of commands, then if a command after the first command was cancelled, the state of the project was not rolled back to the state before the macro was applied. This is now fixed. 3. There remains a bug concerning cancelling a command in a macro which is unaffected by this fix. After cancelling the command, an entry for the macro remains in the undo history. This is a separate bug.
(In reply to David Bailes from comment #3) > Fixed with commits: > https://github.com/audacity/audacity/commit/ > d9663035586a5cf60f4b7e5701c1e98356759691 > https://github.com/audacity/audacity/commit/ > 51b3b0f19a7f7699f029f33b43a9c7e62c1179b4 > (Alas, I forgot to squash before committing.) Minor improvement to the code with this commit: https://github.com/audacity/audacity/commit/a415c3fe3898d917a8d55366f8e6ea6a36ec8e53 > > Notes: > 1. On the basis of comments made by Steve, this bug may have accidentally > fixed a bug on Linux where the track panel does not regain focus after > executing a macro. If this is the case, then this fix will reintroduce that > bug, which should be logged as a separate bug. > > 2. This fix also fixes a bug when a command in a macro is cancelled. Prior > to the fix, if a macro contained a number of commands, then if a command > after the first command was cancelled, the state of the project was not > rolled back to the state before the macro was applied. This is now fixed. > > 3. There remains a bug concerning cancelling a command in a macro which is > unaffected by this fix. After cancelling the command, an entry for the macro > remains in the undo history. This is a separate bug.
Testing on W10 with Audacity 3.0.0 51b3b0f This looks to be fixed, after applying the Macro focus remains in the track the Macro was applied to.
Testing on macOS 10.15.5 Catalina with Audacity 3.0.0 51b3b0f This looks to be fixed, after applying the Macro focus remains in the track the Macro was applied to.
(In reply to David Bailes from comment #3) David "other bugs" should be logged in their own Bugzilla entries. If they are already logged then a reference to the bug numbers here would be useful where you are discussing them.
(In reply to David Bailes from comment #3) Looks good on Linux. Focus is returned to the expected track. If the Macro includes commands to move focus to a different track, Audacity sets focus to the correct track.