Don't clear the undo/redo list when we're just trimming it.

We only allow a certain number of commands on the lists
and trim them when they overflow.  PCB_BASE_EDIT_FRAME and
PL_EDITOR_FRAME implemented this correctly; SCH_EDIT_FRAME
and SYMBOL_EDIT_FRAME did not.
This commit is contained in:
Jeff Young 2024-02-07 14:49:50 +00:00
parent 98bc03919d
commit bce372c8a3
4 changed files with 71 additions and 43 deletions

View File

@ -474,18 +474,29 @@ void SCH_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCou
if( aItemCount == 0 ) if( aItemCount == 0 )
return; return;
UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
for( PICKED_ITEMS_LIST* command : list.m_CommandsList ) if( aItemCount < 0 )
{ {
command->ClearListAndDeleteItems( []( EDA_ITEM* aItem ) list.ClearCommandList();
}
else
{
for( int ii = 0; ii < aItemCount; ii++ )
{
if( list.m_CommandsList.size() == 0 )
break;
PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
list.m_CommandsList.erase( list.m_CommandsList.begin() );
curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
{ {
delete aItem; delete aItem;
} ); } );
delete command; delete curr_cmd; // Delete command
}
} }
list.m_CommandsList.clear();
} }

View File

@ -1556,18 +1556,29 @@ void SYMBOL_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItem
if( aItemCount == 0 ) if( aItemCount == 0 )
return; return;
UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
for( PICKED_ITEMS_LIST* command : list.m_CommandsList ) if( aItemCount < 0 )
{ {
command->ClearListAndDeleteItems( []( EDA_ITEM* aItem ) list.ClearCommandList();
}
else
{
for( int ii = 0; ii < aItemCount; ii++ )
{
if( list.m_CommandsList.size() == 0 )
break;
PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
list.m_CommandsList.erase( list.m_CommandsList.begin() );
curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
{ {
delete aItem; delete aItem;
} ); } );
delete command; delete curr_cmd; // Delete command
}
} }
list.m_CommandsList.clear();
} }

View File

@ -934,13 +934,15 @@ void PL_EDITOR_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCo
if( aItemCount == 0 ) if( aItemCount == 0 )
return; return;
UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
unsigned icnt = list.m_CommandsList.size();
if( aItemCount > 0 ) if( aItemCount < 0 )
icnt = aItemCount; {
list.ClearCommandList();
for( unsigned ii = 0; ii < icnt; ii++ ) }
else
{
for( int ii = 0; ii < aItemCount; ii++ )
{ {
if( list.m_CommandsList.size() == 0 ) if( list.m_CommandsList.size() == 0 )
break; break;
@ -954,6 +956,7 @@ void PL_EDITOR_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCo
} ); } );
delete curr_cmd; // Delete command delete curr_cmd; // Delete command
} }
}
} }

View File

@ -503,13 +503,15 @@ void PCB_BASE_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aIt
if( aItemCount == 0 ) if( aItemCount == 0 )
return; return;
UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList; UNDO_REDO_CONTAINER& list = ( whichList == UNDO_LIST ) ? m_undoList : m_redoList;
unsigned icnt = list.m_CommandsList.size();
if( aItemCount > 0 ) if( aItemCount < 0 )
icnt = aItemCount; {
list.ClearCommandList();
for( unsigned ii = 0; ii < icnt; ii++ ) }
else
{
for( int ii = 0; ii < aItemCount; ii++ )
{ {
if( list.m_CommandsList.size() == 0 ) if( list.m_CommandsList.size() == 0 )
break; break;
@ -519,6 +521,7 @@ void PCB_BASE_EDIT_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aIt
ClearListAndDeleteItems( curr_cmd ); ClearListAndDeleteItems( curr_cmd );
delete curr_cmd; // Delete command delete curr_cmd; // Delete command
} }
}
} }