Focus editor for tab after dragged over for 1500 millis (#149604)

* Focus editor for tab after dragged over for 1500 millis

* 💄

Co-authored-by: Benjamin Pasero <benjamin.pasero@gmail.com>
This commit is contained in:
Mitch Schutt
2022-06-07 09:06:53 -04:00
committed by GitHub
parent c59119306d
commit e3a8e502ad
2 changed files with 23 additions and 3 deletions

View File

@@ -1702,8 +1702,7 @@ export interface IDragAndDropObserverCallbacks {
readonly onDragLeave: (e: DragEvent) => void;
readonly onDrop: (e: DragEvent) => void;
readonly onDragEnd: (e: DragEvent) => void;
readonly onDragOver?: (e: DragEvent) => void;
readonly onDragOver?: (e: DragEvent, dragDuration: number) => void;
}
export class DragAndDropObserver extends Disposable {
@@ -1714,6 +1713,9 @@ export class DragAndDropObserver extends Disposable {
// repeadedly.
private counter: number = 0;
// Allows to measure the duration of the drag operation.
private dragStartTime = 0;
constructor(private readonly element: HTMLElement, private readonly callbacks: IDragAndDropObserverCallbacks) {
super();
@@ -1723,6 +1725,7 @@ export class DragAndDropObserver extends Disposable {
private registerListeners(): void {
this._register(addDisposableListener(this.element, EventType.DRAG_ENTER, (e: DragEvent) => {
this.counter++;
this.dragStartTime = e.timeStamp;
this.callbacks.onDragEnter(e);
}));
@@ -1731,7 +1734,7 @@ export class DragAndDropObserver extends Disposable {
e.preventDefault(); // needed so that the drop event fires (https://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome)
if (this.callbacks.onDragOver) {
this.callbacks.onDragOver(e);
this.callbacks.onDragOver(e, e.timeStamp - this.dragStartTime);
}
}));
@@ -1739,17 +1742,23 @@ export class DragAndDropObserver extends Disposable {
this.counter--;
if (this.counter === 0) {
this.dragStartTime = 0;
this.callbacks.onDragLeave(e);
}
}));
this._register(addDisposableListener(this.element, EventType.DRAG_END, (e: DragEvent) => {
this.counter = 0;
this.dragStartTime = 0;
this.callbacks.onDragEnd(e);
}));
this._register(addDisposableListener(this.element, EventType.DROP, (e: DragEvent) => {
this.counter = 0;
this.dragStartTime = 0;
this.callbacks.onDrop(e);
}));
}