Skip to content

Commit e13875b

Browse files
committed
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
1 parent 51dc319 commit e13875b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/vs/workbench/contrib/webview/browser/pre/host.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
onMessage: hostMessaging.onMessage.bind(hostMessaging),
112112
ready: workerReady,
113113
fakeLoad: !onElectron,
114+
onElectron: onElectron,
114115
rewriteCSP: onElectron
115116
? (csp) => {
116117
return csp.replace(/vscode-resource:(?=(\s|;|$))/g, 'vscode-webview-resource:');

src/vs/workbench/contrib/webview/browser/pre/main.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* onIframeLoaded?: (iframe: HTMLIFrameElement) => void,
1414
* fakeLoad?: boolean,
1515
* rewriteCSP: (existingCSP: string, endpoint?: string) => string,
16+
* onElectron?: boolean
1617
* }} WebviewHost
1718
*/
1819

@@ -286,8 +287,14 @@
286287
// make sure we block the browser from dispatching it. Instead VS Code
287288
// handles these events and will dispatch a copy/paste back to the webview
288289
// if needed
289-
if (isCopyPasteOrCut(e) || isUndoRedo(e)) {
290+
if (isUndoRedo(e)) {
290291
e.preventDefault();
292+
} else if (isCopyPasteOrCut(e)) {
293+
if (host.onElectron) {
294+
e.preventDefault();
295+
} else {
296+
return; // let the browser handle this
297+
}
291298
}
292299

293300
host.postMessage('did-keydown', {

0 commit comments

Comments
 (0)