Index: wp-includes/js/media-editor.js
===================================================================
--- wp-includes/js/media-editor.js	(revision 23494)
+++ wp-includes/js/media-editor.js	(working copy)
@@ -476,7 +476,16 @@
 			}, this );
 
 			workflow.state('gallery-edit').on( 'update', function( selection ) {
-				this.insert( wp.media.gallery.shortcode( selection ).string() );
+				var formatTab = $( '.nav-tab-active' ),
+					sCode = wp.media.gallery.shortcode( selection ).string();
+
+				// If they are on the gallery post format tab, add the
+				// shortcode to the gallery post format field
+				if ( formatTab && 'gallery' === formatTab.data( 'wp-format' ) )
+					$( '#wp_format_gallery' ).val( sCode );
+				// else add it to the editor
+				else
+					this.insert( sCode );
 			}, this );
 
 			workflow.state('embed').on( 'select', function() {
