@@ -310,25 +310,37 @@ class DropOverlay extends Themable {
310
310
const data = this . editorTransfer . getData ( DraggedEditorIdentifier . prototype ) ;
311
311
if ( Array . isArray ( data ) ) {
312
312
const draggedEditor = data [ 0 ] . identifier ;
313
- const targetGroup = ensureTargetGroup ( ) ;
314
313
315
314
const sourceGroup = this . accessor . getGroup ( draggedEditor . groupId ) ;
316
315
if ( sourceGroup ) {
317
- if ( sourceGroup === targetGroup ) {
318
- return ;
316
+ const copyEditor = this . isCopyOperation ( event , draggedEditor ) ;
317
+ let targetGroup : IEditorGroupView | undefined = undefined ;
318
+
319
+ // Optimization: if we move the last editor of an editor group
320
+ // and we are configured to close empty editor groups, we can
321
+ // rather move the entire editor group according to the direction
322
+ if ( this . editorGroupService . partOptions . closeEmptyGroups && sourceGroup . count === 1 && typeof splitDirection === 'number' && ! copyEditor ) {
323
+ targetGroup = this . accessor . moveGroup ( sourceGroup , this . groupView , splitDirection ) ;
319
324
}
320
325
321
- // Open in target group
322
- const options = fillActiveEditorViewState ( sourceGroup , draggedEditor . editor , {
323
- pinned : true , // always pin dropped editor
324
- sticky : sourceGroup . isSticky ( draggedEditor . editor ) , // preserve sticky state
325
- } ) ;
326
+ // In any other case do a normal move/copy operation
327
+ else {
328
+ targetGroup = ensureTargetGroup ( ) ;
329
+ if ( sourceGroup === targetGroup ) {
330
+ return ;
331
+ }
326
332
327
- const copyEditor = this . isCopyOperation ( event , draggedEditor ) ;
328
- if ( ! copyEditor ) {
329
- sourceGroup . moveEditor ( draggedEditor . editor , targetGroup , options ) ;
330
- } else {
331
- sourceGroup . copyEditor ( draggedEditor . editor , targetGroup , options ) ;
333
+ // Open in target group
334
+ const options = fillActiveEditorViewState ( sourceGroup , draggedEditor . editor , {
335
+ pinned : true , // always pin dropped editor
336
+ sticky : sourceGroup . isSticky ( draggedEditor . editor ) , // preserve sticky state
337
+ } ) ;
338
+
339
+ if ( ! copyEditor ) {
340
+ sourceGroup . moveEditor ( draggedEditor . editor , targetGroup , options ) ;
341
+ } else {
342
+ sourceGroup . copyEditor ( draggedEditor . editor , targetGroup , options ) ;
343
+ }
332
344
}
333
345
334
346
// Ensure target has focus
0 commit comments