1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 08:29:27 +02:00

Bug2570 residual: Also handle the case of last saved state in redo

This commit is contained in:
Paul Licameli 2020-11-18 20:37:11 -05:00
parent 7edbad3cd1
commit 0f1c19e97e

View File

@ -1232,6 +1232,7 @@ void ProjectFileManager::Compact()
projectFileIO.ReopenProject(); projectFileIO.ReopenProject();
auto savedState = undoManager.GetSavedState(); auto savedState = undoManager.GetSavedState();
const auto currentState = undoManager.GetCurrentState();
if (savedState < 0) { if (savedState < 0) {
undoManager.StateSaved(); undoManager.StateSaved();
savedState = undoManager.GetSavedState(); savedState = undoManager.GetSavedState();
@ -1240,11 +1241,13 @@ void ProjectFileManager::Compact()
savedState = 0; savedState = 0;
} }
} }
const auto least = std::min<size_t>(savedState, currentState);
const auto greatest = std::max<size_t>(savedState, currentState);
std::vector<const TrackList*> trackLists; std::vector<const TrackList*> trackLists;
undoManager.VisitStates( undoManager.VisitStates(
[&](auto& elem){ trackLists.push_back(elem.state.tracks.get()); }, [&](auto& elem){
savedState, trackLists.push_back(elem.state.tracks.get()); },
undoManager.GetCurrentState() + 1); least, 1 + greatest);
int64_t total = projectFileIO.GetTotalUsage(); int64_t total = projectFileIO.GetTotalUsage();
int64_t used = projectFileIO.GetCurrentUsage(trackLists); int64_t used = projectFileIO.GetCurrentUsage(trackLists);
@ -1264,11 +1267,11 @@ void ProjectFileManager::Compact()
Internat::FormatSize(total - used))); Internat::FormatSize(total - used)));
if (isBatch || dlg.ShowModal() == wxYES) if (isBatch || dlg.ShowModal() == wxYES)
{ {
// We can remove redo states. // We can remove redo states, if they are after the saved state.
undoManager.AbandonRedo(); undoManager.RemoveStates(1 + greatest, undoManager.GetNumStates());
// We can remove all states before the last saved. // We can remove all states before the current and the last saved.
undoManager.RemoveStates(0, savedState); undoManager.RemoveStates(0, least);
// And clear the clipboard, if needed // And clear the clipboard, if needed
if (&mProject == clipboard.Project().lock().get()) if (&mProject == clipboard.Project().lock().get())