Skip to content

Commit

Permalink
Fixes #218626 (#219148)
Browse files Browse the repository at this point in the history
* preventing default on drop events to prevent files from opening in a new window

* adding a fix that addresses #219047

---------

Co-authored-by: Matt Bierner <matb@microsoft.com>
  • Loading branch information
swordensen and mjbvz authored Aug 1, 2024
1 parent ade2c72 commit d00533a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/vs/workbench/contrib/webview/browser/pre/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<meta charset="UTF-8">

<meta http-equiv="Content-Security-Policy"

content="default-src 'none'; script-src 'sha256-ikaxwm2UFoiIKkEZTEU4mnSxpYf3lmsrhy5KqqJZfek=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
content="default-src 'none'; script-src 'sha256-DXeP32g8BdMsVuVabYTmznoTH59F7M7UtV0vXemEFqc=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">


<!-- Disable pinch zooming -->
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -900,6 +914,7 @@
window.addEventListener('dragenter', handleInnerDragStartEvent);
window.addEventListener('dragover', handleInnerDragEvent);
window.addEventListener('drag', handleInnerDragEvent);
window.addEventListener('drop', handleInnerDropEvent);


onDomReady(() => {
Expand Down Expand Up @@ -1184,6 +1199,7 @@
contentWindow.addEventListener('dragenter', handleInnerDragStartEvent);
contentWindow.addEventListener('dragover', handleInnerDragEvent);
contentWindow.addEventListener('drag', handleInnerDragEvent);
contentWindow.addEventListener('drop', handleInnerDropEvent);

unloadMonitor.onIframeLoaded(newFrame);
}
Expand Down

0 comments on commit d00533a

Please sign in to comment.