Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webview: ignore Ctrl+W and Ctrl+N in webview for PWA #164981

Merged
merged 1 commit into from Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/vs/workbench/contrib/webview/browser/pre/index-no-csp.html
Expand Up @@ -589,6 +589,10 @@
} else {
return; // let the browser handle this
}
} else if (!onElectron && (isCloseTab(e) || isNewWindow(e))) {
// Prevent Ctrl+W closing window / Ctrl+N opening new window in PWA.
// (No effect in a regular browser tab.)
e.preventDefault();
}

hostMessaging.postMessage('did-keydown', {
Expand Down Expand Up @@ -655,6 +659,24 @@
return hasMeta && e.key.toLowerCase() === 'f';
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isCloseTab(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'w';
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isNewWindow(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'n';
}

let isHandlingScroll = false;

/**
Expand Down
24 changes: 23 additions & 1 deletion src/vs/workbench/contrib/webview/browser/pre/index.html
Expand Up @@ -5,7 +5,7 @@
<meta charset="UTF-8">

<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'sha256-lC8sxUeeYqUtmkCpPt/OX/HQdE0JbHG1Z3dzrilsRU0=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
content="default-src 'none'; script-src 'sha256-DmsqQtB7vkf/ey+8HeQmSYaMMdiE0Au1IXEkLBE+OtY=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">

<!-- Disable pinch zooming -->
<meta name="viewport"
Expand Down Expand Up @@ -590,6 +590,10 @@
} else {
return; // let the browser handle this
}
} else if (!onElectron && (isCloseTab(e) || isNewWindow(e))) {
// Prevent Ctrl+W closing window / Ctrl+N opening new window in PWA.
// (No effect in a regular browser tab.)
e.preventDefault();
}

hostMessaging.postMessage('did-keydown', {
Expand Down Expand Up @@ -665,6 +669,24 @@
return hasMeta && e.key.toLowerCase() === 's';
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isCloseTab(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'w';
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isNewWindow(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'n';
}

let isHandlingScroll = false;

/**
Expand Down