Skip to content

Commit

Permalink
adding new custom drag event handler to allow event bubbling
Browse files Browse the repository at this point in the history
  • Loading branch information
swordensen committed Apr 5, 2024
1 parent 4f5d9e8 commit 39971e0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/vs/workbench/contrib/webview/browser/webviewElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { loadLocalResource, WebviewResourceResponse } from 'vs/workbench/contrib
import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/browser/themeing';
import { areWebviewContentOptionsEqual, IWebview, WebviewContentOptions, WebviewExtensionDescription, WebviewInitInfo, WebviewMessageReceivedEvent, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewFindDelegate, WebviewFindWidget } from 'vs/workbench/contrib/webview/browser/webviewFindWidget';
import { FromWebviewMessage, KeyEvent, ToWebviewMessage } from 'vs/workbench/contrib/webview/browser/webviewMessages';
import { DragEvent, FromWebviewMessage, KeyEvent, ToWebviewMessage } from 'vs/workbench/contrib/webview/browser/webviewMessages';
import { decodeAuthority, webviewGenericCspSource, webviewRootResourceAuthority } from 'vs/workbench/contrib/webview/common/webview';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { CodeWindow } from 'vs/base/browser/window';
Expand Down Expand Up @@ -310,6 +310,10 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this._startBlockingIframeDragEvents();
}));

this._register(this.on('drag', (event) => {
this.handleDragEvent('drag', event);
}));

if (initInfo.options.enableFindWidget) {
this._webviewFindWidget = this._register(instantiationService.createInstance(WebviewFindWidget, this));
}
Expand Down Expand Up @@ -697,6 +701,17 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this.window?.dispatchEvent(emulatedKeyboardEvent);
}

private handleDragEvent(type: 'drag', event: DragEvent) {
// Create a fake KeyboardEvent from the data provided
const emulatedDragEvent = new DragEvent(type, event);
// Force override the target
Object.defineProperty(emulatedDragEvent, 'target', {
get: () => this.element,
});
// And re-dispatch
this.window?.dispatchEvent(emulatedDragEvent);
}

windowDidDragStart(): void {
// Webview break drag and dropping around the main window (no events are generated when you are over them)
// Work around this by disabling pointer events during the drag.
Expand Down

0 comments on commit 39971e0

Please sign in to comment.