Fix undo state problem