Skip to content

Commit

Permalink
Only prevent default for copy paste in webviews when on electron
Browse files Browse the repository at this point in the history
Fixes #106383

For web VS Code, we want the browser to handle these events instead. This means we can skip the dispatch entirely
  • Loading branch information
mjbvz committed Sep 14, 2020
1 parent 51dc319 commit e13875b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/webview/browser/pre/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:');
Expand Down
9 changes: 8 additions & 1 deletion src/vs/workbench/contrib/webview/browser/pre/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* onIframeLoaded?: (iframe: HTMLIFrameElement) => void,
* fakeLoad?: boolean,
* rewriteCSP: (existingCSP: string, endpoint?: string) => string,
* onElectron?: boolean
* }} WebviewHost
*/

Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit e13875b

Please sign in to comment.