diff --git a/src/vs/workbench/contrib/webview/browser/pre/index.html b/src/vs/workbench/contrib/webview/browser/pre/index.html index f46e124042850..6a1f3d459abf6 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/index.html +++ b/src/vs/workbench/contrib/webview/browser/pre/index.html @@ -5,8 +5,7 @@ + content="default-src 'none'; script-src 'sha256-DXeP32g8BdMsVuVabYTmznoTH59F7M7UtV0vXemEFqc=' 'self'; frame-src 'self'; style-src 'unsafe-inline';"> @@ -799,13 +798,28 @@ function handleInnerDragEvent(/** @type {DragEvent} */ e) { + /** + * To ensure that the drop event always fires as expected, you should always include a preventDefault() call in the part of your code which handles the dragover event. + * source: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drop_event + **/ + e.preventDefault(); + if (!e.dataTransfer) { return; } - hostMessaging.postMessage('drag', { - shiftKey: e.shiftKey - }); + + // Only handle drags from outside editor for now + if (e.dataTransfer.items.length && Array.prototype.every.call(e.dataTransfer.items, item => item.kind === 'file')) { + hostMessaging.postMessage('drag', { + shiftKey: e.shiftKey + }); + } + + } + + function handleInnerDropEvent(/**@type {DragEvent} */e) { + e.preventDefault(); } /** @@ -900,6 +914,7 @@ window.addEventListener('dragenter', handleInnerDragStartEvent); window.addEventListener('dragover', handleInnerDragEvent); window.addEventListener('drag', handleInnerDragEvent); + window.addEventListener('drop', handleInnerDropEvent); onDomReady(() => { @@ -1184,6 +1199,7 @@ contentWindow.addEventListener('dragenter', handleInnerDragStartEvent); contentWindow.addEventListener('dragover', handleInnerDragEvent); contentWindow.addEventListener('drag', handleInnerDragEvent); + contentWindow.addEventListener('drop', handleInnerDropEvent); unloadMonitor.onIframeLoaded(newFrame); }