Don't allow undo record to get pushed during an undo.

When doing a schematic cleanup, for instance, we were breaking wires
and pushing undo records on to the stack.  Needless to say, this was
pretty unexpected for the rest of the undo framework and caused all
kinds of mayhem (including crashes in some cases).

Fixes https://gitlab.com/kicad/code/kicad/issues/8704
This commit is contained in:
Jeff Young 2021-07-08 19:41:28 +01:00
parent e895af4ec6
commit 46701c1195
1 changed files with 9 additions and 4 deletions

View File

@ -1166,18 +1166,23 @@ int SCH_EDITOR_CONTROL::Undo( const TOOL_EVENT& aEvent )
/* Get the old list */ /* Get the old list */
PICKED_ITEMS_LIST* List = m_frame->PopCommandFromUndoList(); PICKED_ITEMS_LIST* List = m_frame->PopCommandFromUndoList();
size_t num_undos = m_frame->m_undoList.m_CommandsList.size();
/* Undo the command */ /* Undo the command */
m_frame->PutDataInPreviousState( List ); m_frame->PutDataInPreviousState( List );
/* Put the old list in RedoList */
List->ReversePickersListOrder();
m_frame->PushCommandToRedoList( List );
m_frame->SetSheetNumberAndCount(); m_frame->SetSheetNumberAndCount();
m_frame->TestDanglingEnds(); m_frame->TestDanglingEnds();
m_frame->OnPageSettingsChange(); m_frame->OnPageSettingsChange();
// If we modified anything during cleanup we don't want it going on the undolist
while( m_frame->m_undoList.m_CommandsList.size() > num_undos )
delete m_frame->PopCommandFromUndoList();
// Now push the old command to the RedoList
List->ReversePickersListOrder();
m_frame->PushCommandToRedoList( List );
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection(); m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
m_frame->SyncView(); m_frame->SyncView();