From e13875b77c89b95f20ccb5667e14ff164c198e57 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 14 Sep 2020 16:08:08 -0700 Subject: [PATCH] Only prevent default for copy paste in webviews when on electron Fixes #106383 For web VS Code, we want the browser to handle these events instead. This means we can skip the dispatch entirely --- src/vs/workbench/contrib/webview/browser/pre/host.js | 1 + src/vs/workbench/contrib/webview/browser/pre/main.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/webview/browser/pre/host.js b/src/vs/workbench/contrib/webview/browser/pre/host.js index c63f6122aeeb6..16bc8e156df3d 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/host.js +++ b/src/vs/workbench/contrib/webview/browser/pre/host.js @@ -111,6 +111,7 @@ onMessage: hostMessaging.onMessage.bind(hostMessaging), ready: workerReady, fakeLoad: !onElectron, + onElectron: onElectron, rewriteCSP: onElectron ? (csp) => { return csp.replace(/vscode-resource:(?=(\s|;|$))/g, 'vscode-webview-resource:'); diff --git a/src/vs/workbench/contrib/webview/browser/pre/main.js b/src/vs/workbench/contrib/webview/browser/pre/main.js index b2f2ed0ff9d05..0aede20701c5e 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/main.js +++ b/src/vs/workbench/contrib/webview/browser/pre/main.js @@ -13,6 +13,7 @@ * onIframeLoaded?: (iframe: HTMLIFrameElement) => void, * fakeLoad?: boolean, * rewriteCSP: (existingCSP: string, endpoint?: string) => string, + * onElectron?: boolean * }} WebviewHost */ @@ -286,8 +287,14 @@ // make sure we block the browser from dispatching it. Instead VS Code // handles these events and will dispatch a copy/paste back to the webview // if needed - if (isCopyPasteOrCut(e) || isUndoRedo(e)) { + if (isUndoRedo(e)) { e.preventDefault(); + } else if (isCopyPasteOrCut(e)) { + if (host.onElectron) { + e.preventDefault(); + } else { + return; // let the browser handle this + } } host.postMessage('did-keydown', {