1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/editordroptarget';
import { Extensions as DragAndDropExtensions, LocalSelectionTransfer, DraggedEditorIdentifier, ResourcesDropHandler, DraggedEditorGroupIdentifier, containsDragType, CodeDataTransfers, DraggedTreeItemsIdentifier, extractTreeDropData, IDragAndDropContributionRegistry } from 'vs/workbench/browser/dnd';
import { addDisposableListener, EventType, EventHelper, isAncestor, DragAndDropObserver } from 'vs/base/browser/dom';
import { IEditorGroupsAccessor, IEditorGroupView, fillActiveEditorViewState } from 'vs/workbench/browser/parts/editor/editor';
import { EDITOR_DRAG_AND_DROP_BACKGROUND } from 'vs/workbench/common/theme';
import { IThemeService, Themable } from 'vs/platform/theme/common/themeService';
import { activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { IEditorIdentifier, EditorInputCapabilities, IUntypedEditorInput } from 'vs/workbench/common/editor';
import { isMacintosh, isWeb } from 'vs/base/common/platform';
import { GroupDirection, IEditorGroupsService, IMergeGroupOptions, MergeGroupMode } from 'vs/workbench/services/editor/common/editorGroupsService';
import { toDisposable } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { RunOnceScheduler } from 'vs/base/common/async';
import { DataTransfers } from 'vs/base/browser/dnd';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { assertIsDefined, assertAllDefined } from 'vs/base/common/types';
import { ITreeViewsService } from 'vs/workbench/services/views/browser/treeViewsService';
import { isTemporaryWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Registry } from 'vs/platform/registry/common/platform';
interface IDropOperation {
splitDirection?: GroupDirection;
}
function isDragIntoEditorEvent(configurationService: IConfigurationService, e: DragEvent): boolean {
if (!configurationService.getValue<boolean>('workbench.experimental.editor.dragAndDropIntoEditor.enabled')) {
return false;
}
return e.shiftKey;
}
class DropOverlay extends Themable {
private static readonly OVERLAY_ID = 'monaco-workbench-editor-drop-overlay';
private container: HTMLElement | undefined;
private overlay: HTMLElement | undefined;
private currentDropOperation: IDropOperation | undefined;
private _disposed: boolean | undefined;
private cleanupOverlayScheduler: RunOnceScheduler;
private readonly editorTransfer = LocalSelectionTransfer.getInstance<DraggedEditorIdentifier>();
private readonly groupTransfer = LocalSelectionTransfer.getInstance<DraggedEditorGroupIdentifier>();
private readonly treeItemsTransfer = LocalSelectionTransfer.getInstance<DraggedTreeItemsIdentifier>();
constructor(
private accessor: IEditorGroupsAccessor,
private groupView: IEditorGroupView,
@IThemeService themeService: IThemeService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IEditorService private readonly editorService: IEditorService,
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@ITreeViewsService private readonly treeViewsDragAndDropService: ITreeViewsService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService
) {
super(themeService);
this.cleanupOverlayScheduler = this._register(new RunOnceScheduler(() => this.dispose(), 300));
this.create();
}
get disposed(): boolean {
return !!this._disposed;
}
private create(): void {
const overlayOffsetHeight = this.getOverlayOffsetHeight();
// Container
const container = this.container = document.createElement('div');
container.id = DropOverlay.OVERLAY_ID;
container.style.top = `${overlayOffsetHeight}px`;
// Parent
this.groupView.element.appendChild(container);
this.groupView.element.classList.add('dragged-over');
this._register(toDisposable(() => {
this.groupView.element.removeChild(container);
this.groupView.element.classList.remove('dragged-over');
}));
// Overlay
this.overlay = document.createElement('div');
this.overlay.classList.add('editor-group-overlay-indicator');
container.appendChild(this.overlay);
// Overlay Event Handling
this.registerListeners(container);
// Styles
this.updateStyles();
}
protected override updateStyles(): void {
const overlay = assertIsDefined(this.overlay);
// Overlay drop background
overlay.style.backgroundColor = this.getColor(EDITOR_DRAG_AND_DROP_BACKGROUND) || '';
// Overlay contrast border (if any)
const activeContrastBorderColor = this.getColor(activeContrastBorder);
overlay.style.outlineColor = activeContrastBorderColor || '';
overlay.style.outlineOffset = activeContrastBorderColor ? '-2px' : '';
overlay.style.outlineStyle = activeContrastBorderColor ? 'dashed' : '';
overlay.style.outlineWidth = activeContrastBorderColor ? '2px' : '';
}
private registerListeners(container: HTMLElement): void {
this._register(new DragAndDropObserver(container, {
onDragEnter: e => undefined,
onDragOver: e => {
if (isDragIntoEditorEvent(this.configurationService, e)) {
this.dispose();
return;
}
const isDraggingGroup = this.groupTransfer.hasData(DraggedEditorGroupIdentifier.prototype);
const isDraggingEditor = this.editorTransfer.hasData(DraggedEditorIdentifier.prototype);
// Update the dropEffect to "copy" if there is no local data to be dragged because
// in that case we can only copy the data into and not move it from its source
if (!isDraggingEditor && !isDraggingGroup && e.dataTransfer) {
e.dataTransfer.dropEffect = 'copy';
}
// Find out if operation is valid
let isCopy = true;
if (isDraggingGroup) {
isCopy = this.isCopyOperation(e);
} else if (isDraggingEditor) {
const data = this.editorTransfer.getData(DraggedEditorIdentifier.prototype);
if (Array.isArray(data)) {
isCopy = this.isCopyOperation(e, data[0].identifier);
}
}
if (!isCopy) {
const sourceGroupView = this.findSourceGroupView();
if (sourceGroupView === this.groupView) {
if (isDraggingGroup || (isDraggingEditor && sourceGroupView.count < 2)) {
this.hideOverlay();
return; // do not allow to drop group/editor on itself if this results in an empty group
}
}
}
// Position overlay and conditionally enable or disable
// editor group splitting support based on setting and
// keymodifiers used.
let splitOnDragAndDrop = !!this.editorGroupService.partOptions.splitOnDragAndDrop;
if (this.isToggleSplitOperation(e)) {
splitOnDragAndDrop = !splitOnDragAndDrop;
}
this.positionOverlay(e.offsetX, e.offsetY, isDraggingGroup, splitOnDragAndDrop);
// Make sure to stop any running cleanup scheduler to remove the overlay
if (this.cleanupOverlayScheduler.isScheduled()) {
this.cleanupOverlayScheduler.cancel();
}
},
onDragLeave: e => this.dispose(),
onDragEnd: e => this.dispose(),
onDrop: e => {
EventHelper.stop(e, true);
// Dispose overlay
this.dispose();
// Handle drop if we have a valid operation
if (this.currentDropOperation) {
this.handleDrop(e, this.currentDropOperation.splitDirection);
}
}
}));
this._register(addDisposableListener(container, EventType.MOUSE_OVER, () => {
// Under some circumstances we have seen reports where the drop overlay is not being
// cleaned up and as such the editor area remains under the overlay so that you cannot
// type into the editor anymore. This seems related to using VMs and DND via host and
// guest OS, though some users also saw it without VMs.
// To protect against this issue we always destroy the overlay as soon as we detect a
// mouse event over it. The delay is used to guarantee we are not interfering with the
// actual DROP event that can also trigger a mouse over event.
if (!this.cleanupOverlayScheduler.isScheduled()) {
this.cleanupOverlayScheduler.schedule();
}
}));
}
private findSourceGroupView(): IEditorGroupView | undefined {
// Check for group transfer
if (this.groupTransfer.hasData(DraggedEditorGroupIdentifier.prototype)) {
const data = this.groupTransfer.getData(DraggedEditorGroupIdentifier.prototype);
if (Array.isArray(data)) {
return this.accessor.getGroup(data[0].identifier);
}
}
// Check for editor transfer
else if (this.editorTransfer.hasData(DraggedEditorIdentifier.prototype)) {
const data = this.editorTransfer.getData(DraggedEditorIdentifier.prototype);
if (Array.isArray(data)) {
return this.accessor.getGroup(data[0].identifier.groupId);
}
}
return undefined;
}
private async handleDrop(event: DragEvent, splitDirection?: GroupDirection): Promise<void> {
// Determine target group
const ensureTargetGroup = () => {
let targetGroup: IEditorGroupView;
if (typeof splitDirection === 'number') {
targetGroup = this.accessor.addGroup(this.groupView, splitDirection);
} else {
targetGroup = this.groupView;
}
return targetGroup;
};
// Check for group transfer
if (this.groupTransfer.hasData(DraggedEditorGroupIdentifier.prototype)) {
const data = this.groupTransfer.getData(DraggedEditorGroupIdentifier.prototype);
if (Array.isArray(data)) {
const sourceGroup = this.accessor.getGroup(data[0].identifier);
if (sourceGroup) {
if (typeof splitDirection !== 'number' && sourceGroup === this.groupView) {
return;
}
// Split to new group
let targetGroup: IEditorGroupView | undefined;
if (typeof splitDirection === 'number') {
if (this.isCopyOperation(event)) {
targetGroup = this.accessor.copyGroup(sourceGroup, this.groupView, splitDirection);
} else {
targetGroup = this.accessor.moveGroup(sourceGroup, this.groupView, splitDirection);
}
}
// Merge into existing group
else {
let mergeGroupOptions: IMergeGroupOptions | undefined = undefined;
if (this.isCopyOperation(event)) {
mergeGroupOptions = { mode: MergeGroupMode.COPY_EDITORS };
}
this.accessor.mergeGroup(sourceGroup, this.groupView, mergeGroupOptions);
}
if (targetGroup) {
this.accessor.activateGroup(targetGroup);
}
}
this.groupTransfer.clearData(DraggedEditorGroupIdentifier.prototype);
}
}
// Check for editor transfer
else if (this.editorTransfer.hasData(DraggedEditorIdentifier.prototype)) {
const data = this.editorTransfer.getData(DraggedEditorIdentifier.prototype);
if (Array.isArray(data)) {
const draggedEditor = data[0].identifier;
const targetGroup = ensureTargetGroup();
const sourceGroup = this.accessor.getGroup(draggedEditor.groupId);
if (sourceGroup) {
if (sourceGroup === targetGroup) {
return;
}
// Open in target group
const options = fillActiveEditorViewState(sourceGroup, draggedEditor.editor, {
pinned: true, // always pin dropped editor
sticky: sourceGroup.isSticky(draggedEditor.editor), // preserve sticky state
});
const copyEditor = this.isCopyOperation(event, draggedEditor);
if (!copyEditor) {
sourceGroup.moveEditor(draggedEditor.editor, targetGroup, options);
} else {
sourceGroup.copyEditor(draggedEditor.editor, targetGroup, options);
}
// Ensure target has focus
targetGroup.focus();
}
this.editorTransfer.clearData(DraggedEditorIdentifier.prototype);
}
}
// Check for tree items
else if (this.treeItemsTransfer.hasData(DraggedTreeItemsIdentifier.prototype)) {
const data = this.treeItemsTransfer.getData(DraggedTreeItemsIdentifier.prototype);
if (Array.isArray(data)) {
const editors: IUntypedEditorInput[] = [];
for (const id of data) {
const dataTransferItem = await this.treeViewsDragAndDropService.removeDragOperationTransfer(id.identifier);
if (dataTransferItem) {
const treeDropData = await extractTreeDropData(dataTransferItem);
editors.push(...treeDropData.map(editor => ({ ...editor, options: { ...editor.options, pinned: true } })));
}
}
this.editorService.openEditors(editors, ensureTargetGroup(), { validateTrust: true });
}
this.treeItemsTransfer.clearData(DraggedTreeItemsIdentifier.prototype);
}
// Check for URI transfer
else {
const dropHandler = this.instantiationService.createInstance(ResourcesDropHandler, { allowWorkspaceOpen: !isWeb || isTemporaryWorkspace(this.contextService.getWorkspace()) });
dropHandler.handleDrop(event, () => ensureTargetGroup(), targetGroup => targetGroup?.focus());
}
}
private isCopyOperation(e: DragEvent, draggedEditor?: IEditorIdentifier): boolean {
if (draggedEditor?.editor.hasCapability(EditorInputCapabilities.Singleton)) {
return false; // Singleton editors cannot be split
}
return (e.ctrlKey && !isMacintosh) || (e.altKey && isMacintosh);
}
private isToggleSplitOperation(e: DragEvent): boolean {
return (e.altKey && !isMacintosh) || (e.shiftKey && isMacintosh);
}
private positionOverlay(mousePosX: number, mousePosY: number, isDraggingGroup: boolean, enableSplitting: boolean): void {
const preferSplitVertically = this.accessor.partOptions.openSideBySideDirection === 'right';
const editorControlWidth = this.groupView.element.clientWidth;
const editorControlHeight = this.groupView.element.clientHeight - this.getOverlayOffsetHeight();
let edgeWidthThresholdFactor: number;
let edgeHeightThresholdFactor: number;
if (enableSplitting) {
if (isDraggingGroup) {
edgeWidthThresholdFactor = preferSplitVertically ? 0.3 : 0.1; // give larger threshold when dragging group depending on preferred split direction
} else {
edgeWidthThresholdFactor = 0.1; // 10% threshold to split if dragging editors
}
if (isDraggingGroup) {
edgeHeightThresholdFactor = preferSplitVertically ? 0.1 : 0.3; // give larger threshold when dragging group depending on preferred split direction
} else {
edgeHeightThresholdFactor = 0.1; // 10% threshold to split if dragging editors
}
} else {
edgeWidthThresholdFactor = 0;
edgeHeightThresholdFactor = 0;
}
const edgeWidthThreshold = editorControlWidth * edgeWidthThresholdFactor;
const edgeHeightThreshold = editorControlHeight * edgeHeightThresholdFactor;
const splitWidthThreshold = editorControlWidth / 3; // offer to split left/right at 33%
const splitHeightThreshold = editorControlHeight / 3; // offer to split up/down at 33%
// Enable to debug the drop threshold square
// let child = this.overlay.children.item(0) as HTMLElement || this.overlay.appendChild(document.createElement('div'));
// child.style.backgroundColor = 'red';
// child.style.position = 'absolute';
// child.style.width = (groupViewWidth - (2 * edgeWidthThreshold)) + 'px';
// child.style.height = (groupViewHeight - (2 * edgeHeightThreshold)) + 'px';
// child.style.left = edgeWidthThreshold + 'px';
// child.style.top = edgeHeightThreshold + 'px';
// No split if mouse is above certain threshold in the center of the view
let splitDirection: GroupDirection | undefined;
if (
mousePosX > edgeWidthThreshold && mousePosX < editorControlWidth - edgeWidthThreshold &&
mousePosY > edgeHeightThreshold && mousePosY < editorControlHeight - edgeHeightThreshold
) {
splitDirection = undefined;
}
// Offer to split otherwise
else {
// User prefers to split vertically: offer a larger hitzone
// for this direction like so:
// ----------------------------------------------
// | | SPLIT UP | |
// | SPLIT |-----------------------| SPLIT |
// | | MERGE | |
// | LEFT |-----------------------| RIGHT |
// | | SPLIT DOWN | |
// ----------------------------------------------
if (preferSplitVertically) {
if (mousePosX < splitWidthThreshold) {
splitDirection = GroupDirection.LEFT;
} else if (mousePosX > splitWidthThreshold * 2) {
splitDirection = GroupDirection.RIGHT;
} else if (mousePosY < editorControlHeight / 2) {
splitDirection = GroupDirection.UP;
} else {
splitDirection = GroupDirection.DOWN;
}
}
// User prefers to split horizontally: offer a larger hitzone
// for this direction like so:
// ----------------------------------------------
// | SPLIT UP |
// |--------------------------------------------|
// | SPLIT LEFT | MERGE | SPLIT RIGHT |
// |--------------------------------------------|
// | SPLIT DOWN |
// ----------------------------------------------
else {
if (mousePosY < splitHeightThreshold) {
splitDirection = GroupDirection.UP;
} else if (mousePosY > splitHeightThreshold * 2) {
splitDirection = GroupDirection.DOWN;
} else if (mousePosX < editorControlWidth / 2) {
splitDirection = GroupDirection.LEFT;
} else {
splitDirection = GroupDirection.RIGHT;
}
}
}
// Draw overlay based on split direction
switch (splitDirection) {
case GroupDirection.UP:
this.doPositionOverlay({ top: '0', left: '0', width: '100%', height: '50%' });
break;
case GroupDirection.DOWN:
this.doPositionOverlay({ top: '50%', left: '0', width: '100%', height: '50%' });
break;
case GroupDirection.LEFT:
this.doPositionOverlay({ top: '0', left: '0', width: '50%', height: '100%' });
break;
case GroupDirection.RIGHT:
this.doPositionOverlay({ top: '0', left: '50%', width: '50%', height: '100%' });
break;
default:
this.doPositionOverlay({ top: '0', left: '0', width: '100%', height: '100%' });
}
// Make sure the overlay is visible now
const overlay = assertIsDefined(this.overlay);
overlay.style.opacity = '1';
// Enable transition after a timeout to prevent initial animation
setTimeout(() => overlay.classList.add('overlay-move-transition'), 0);
// Remember as current split direction
this.currentDropOperation = { splitDirection };
}
private doPositionOverlay(options: { top: string; left: string; width: string; height: string }): void {
const [container, overlay] = assertAllDefined(this.container, this.overlay);
// Container
const offsetHeight = this.getOverlayOffsetHeight();
if (offsetHeight) {
container.style.height = `calc(100% - ${offsetHeight}px)`;
} else {
container.style.height = '100%';
}
// Overlay
overlay.style.top = options.top;
overlay.style.left = options.left;
overlay.style.width = options.width;
overlay.style.height = options.height;
}
private getOverlayOffsetHeight(): number {
// With tabs and opened editors: use the area below tabs as drop target
if (!this.groupView.isEmpty && this.accessor.partOptions.showTabs) {
return this.groupView.titleHeight.offset;
}
// Without tabs or empty group: use entire editor area as drop target
return 0;
}
private hideOverlay(): void {
const overlay = assertIsDefined(this.overlay);
// Reset overlay
this.doPositionOverlay({ top: '0', left: '0', width: '100%', height: '100%' });
overlay.style.opacity = '0';
overlay.classList.remove('overlay-move-transition');
// Reset current operation
this.currentDropOperation = undefined;
}
contains(element: HTMLElement): boolean {
return element === this.container || element === this.overlay;
}
override dispose(): void {
super.dispose();
this._disposed = true;
}
}
export interface IEditorDropTargetDelegate {
/**
* A helper to figure out if the drop target contains the provided group.
*/
containsGroup?(groupView: IEditorGroupView): boolean;
}
export class EditorDropTarget extends Themable {
private _overlay?: DropOverlay;
private counter = 0;
private readonly editorTransfer = LocalSelectionTransfer.getInstance<DraggedEditorIdentifier>();
private readonly groupTransfer = LocalSelectionTransfer.getInstance<DraggedEditorGroupIdentifier>();
constructor(
private accessor: IEditorGroupsAccessor,
private container: HTMLElement,
private readonly delegate: IEditorDropTargetDelegate,
@IThemeService themeService: IThemeService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super(themeService);
this.registerListeners();
}
private get overlay(): DropOverlay | undefined {
if (this._overlay && !this._overlay.disposed) {
return this._overlay;
}
return undefined;
}
private registerListeners(): void {
this._register(addDisposableListener(this.container, EventType.DRAG_ENTER, e => this.onDragEnter(e)));
this._register(addDisposableListener(this.container, EventType.DRAG_LEAVE, () => this.onDragLeave()));
[this.container, window].forEach(node => this._register(addDisposableListener(node as HTMLElement, EventType.DRAG_END, () => this.onDragEnd())));
}
private onDragEnter(event: DragEvent): void {
if (isDragIntoEditorEvent(this.configurationService, event)) {
return;
}
this.counter++;
// Validate transfer
if (
!this.editorTransfer.hasData(DraggedEditorIdentifier.prototype) &&
!this.groupTransfer.hasData(DraggedEditorGroupIdentifier.prototype) &&
event.dataTransfer
) {
const dndContributions = Registry.as<IDragAndDropContributionRegistry>(DragAndDropExtensions.DragAndDropContribution).getAll();
const dndContributionKeys = Array.from(dndContributions).map(e => e.dataFormatKey);
if (!containsDragType(event, DataTransfers.FILES, CodeDataTransfers.FILES, DataTransfers.RESOURCES, CodeDataTransfers.EDITORS, ...dndContributionKeys)) { // see https://github.com/microsoft/vscode/issues/25789
event.dataTransfer.dropEffect = 'none';
return; // unsupported transfer
}
}
// Signal DND start
this.updateContainer(true);
const target = event.target as HTMLElement;
if (target) {
// Somehow we managed to move the mouse quickly out of the current overlay, so destroy it
if (this.overlay && !this.overlay.contains(target)) {
this.disposeOverlay();
}
// Create overlay over target
if (!this.overlay) {
const targetGroupView = this.findTargetGroupView(target);
if (targetGroupView) {
this._overlay = this.instantiationService.createInstance(DropOverlay, this.accessor, targetGroupView);
}
}
}
}
private onDragLeave(): void {
this.counter--;
if (this.counter === 0) {
this.updateContainer(false);
}
}
private onDragEnd(): void {
this.counter = 0;
this.updateContainer(false);
this.disposeOverlay();
}
private findTargetGroupView(child: HTMLElement): IEditorGroupView | undefined {
const groups = this.accessor.groups;
return groups.find(groupView => isAncestor(child, groupView.element) || this.delegate.containsGroup?.(groupView));
}
private updateContainer(isDraggedOver: boolean): void {
this.container.classList.toggle('dragged-over', isDraggedOver);
}
override dispose(): void {
super.dispose();
this.disposeOverlay();
}
private disposeOverlay(): void {
if (this.overlay) {
this.overlay.dispose();
this._overlay = undefined;
}
}
}
|