Skip to content

Commit 387a423

Browse files
authored
1 parent e1d8abf commit 387a423

File tree

1 file changed

+67
-4
lines changed
  • packages/databricks-vscode/webview-ui

1 file changed

+67
-4
lines changed

packages/databricks-vscode/webview-ui/job.html

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@
148148
<div class="output spinner" id="output">
149149
<header>Output</header>
150150
<vscode-progress-ring id="spinner"></vscode-progress-ring>
151-
<iframe id="frame"></iframe>
151+
<iframe
152+
id="frame"
153+
sandbox="allow-same-origin allow-pointer-lock allow-scripts allow-downloads allow-forms"
154+
allow="cross-origin-isolated; clipboard-read; clipboard-write;"
155+
></iframe>
152156
<pre id="stdout"></pre>
153157
<div class="alert-error" id="error">
154158
<span class="error-icon">
@@ -213,6 +217,8 @@
213217
</div>
214218
</div>
215219
<script>
220+
const isMac = navigator.platform.indexOf("Mac") >= 0;
221+
216222
class PageHandler {
217223
formatDuration(duration) {
218224
if (duration < 0 || duration === undefined) {
@@ -257,13 +263,69 @@
257263
cl.remove("error");
258264
cl.add("html");
259265

260-
var frame = document.getElementById("frame");
261-
var frame = frame.contentWindow || frame.contentDocument;
266+
const frameEl = document.getElementById("frame");
267+
var frame =
268+
frameEl.contentWindow || frameEl.contentDocument;
262269
if (frame.document) frame = frame.document;
263270

264271
frame.open();
265272
frame.write(html);
266273
frame.close();
274+
275+
if (isMac) {
276+
// The clipboard doesn't work in iframes embedded in webviews
277+
// See https://github.com/microsoft/vscode/issues/65452
278+
279+
// forward keydown events to the webview and handle CTRL-A
280+
frame.addEventListener("keydown", (e) => {
281+
window.dispatchEvent(
282+
new KeyboardEvent("keydown", e)
283+
);
284+
});
285+
286+
// forward copy commands to the iFrame
287+
document.addEventListener("copy", (e) => {
288+
frame.execCommand("copy");
289+
});
290+
291+
// forward context menu events to the webview and make
292+
// clientX and clientY relative to the webview
293+
frame.addEventListener("contextmenu", (e) => {
294+
const rect = frameEl.getBoundingClientRect();
295+
window.document.documentElement.dispatchEvent(
296+
new MouseEvent("contextmenu", {
297+
altKey: e.altKey,
298+
bubbles: e.bubbles,
299+
button: e.button,
300+
buttons: e.buttons,
301+
cancelable: e.cancelable,
302+
clientX: e.clientX + rect.left,
303+
clientY: e.clientY + rect.top,
304+
composed: e.composed,
305+
ctrlKey: e.ctrlKey,
306+
detail: e.detail,
307+
metaKey: e.metaKey,
308+
modifierAltGraph: e.modifierAltGraph,
309+
modifierCapsLock: e.modifierCapsLock,
310+
modifierFn: e.modifierFn,
311+
modifierFnLock: e.modifierFnLock,
312+
modifierHyper: e.modifierHyper,
313+
modifierNumLock: e.modifierNumLock,
314+
modifierScrollLock: e.modifierScrollLock,
315+
modifierSuper: e.modifierSuper,
316+
modifierSymbol: e.modifierSymbol,
317+
modifierSymbolLock: e.modifierSymbolLock,
318+
movementX: e.movementX,
319+
movementY: e.movementY,
320+
relatedTarget: e.relatedTarget,
321+
screenX: e.screenX,
322+
screenY: e.screenY,
323+
shiftKey: e.shiftKey,
324+
view: e.view,
325+
})
326+
);
327+
});
328+
}
267329
}
268330

269331
setStdout(stdout) {
@@ -299,7 +361,8 @@
299361

300362
if (vscode) {
301363
window.addEventListener("message", (event) => {
302-
page[event.data.fn](...event.data.args);
364+
page[event.data.fn] &&
365+
page[event.data.fn](...event.data.args);
303366
});
304367
} else {
305368
// test code for iterating on the page in a web browser

0 commit comments

Comments
 (0)