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

Prevent F1 from opening browser help in webviews #204499

Merged
merged 3 commits into from Feb 6, 2024
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
20 changes: 19 additions & 1 deletion src/vs/workbench/contrib/webview/browser/pre/index-no-csp.html
Expand Up @@ -596,7 +596,7 @@
} else {
return; // let the browser handle this
}
} else if (!onElectron && (isCloseTab(e) || isNewWindow(e))) {
} else if (!onElectron && (isCloseTab(e) || isNewWindow(e) || isHelp(e) || isRefresh(e))) {
// Prevent Ctrl+W closing window / Ctrl+N opening new window in PWA.
// (No effect in a regular browser tab.)
e.preventDefault();
Expand Down Expand Up @@ -701,6 +701,24 @@
return hasMeta && e.keyCode === 78;
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isHelp(e) {
// 112: keyCode of "F1"
return e.keyCode === 112;
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isRefresh(e) {
// 116: keyCode of "F5"
return e.keyCode === 116;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the keyCode property being deprecated, in favor of using the KeyboardEvent.code property?

}

let isHandlingScroll = false;

/**
Expand Down
22 changes: 20 additions & 2 deletions 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-frEVWVmmI4TWHGHXZaCTWqGQI9jv+i8hv+sOa87Gqlc=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
content="default-src 'none'; script-src 'sha256-MbYFw/X6HjRtVlnfFTL3ylPDt3RsDzWrYVjfrzKJbMA=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">

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

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isHelp(e) {
// 112: keyCode of "F1"
return e.keyCode === 112;
}

/**
* @param {KeyboardEvent} e
* @return {boolean}
*/
function isRefresh(e) {
// 116: keyCode of "F5"
return e.keyCode === 116;
}

let isHandlingScroll = false;

/**
Expand Down