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

Disable default context menu on windows #608

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/vscode-extension/src/webview/components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,28 @@ function Preview({
}
}

function onContextMenu(e: MouseEvent<HTMLDivElement>) {
e.preventDefault();
}

useEffect(() => {
// this is a fix that disables context menu on windows https://github.com/microsoft/vscode/issues/139824
// there is an active backlog item that aims to change the behavior of context menu, so it might not be necessary
// in the future https://github.com/microsoft/vscode/issues/225411
function onContextMenu(e: any) {
e.stopImmediatePropagation();
}

window.addEventListener("contextmenu", onContextMenu, true);

function onBlurChange() {
if (!document.hasFocus()) {
setIsPanning(false);
setIsMultiTouching(false);
setIsPressing(false);
}
}
addEventListener("blur", onBlurChange, true);
return () => removeEventListener("blur", onBlurChange, true);
document.addEventListener("blur", onBlurChange, true);
return () => {
window.removeEventListener("contextmenu", onContextMenu);
document.removeEventListener("blur", onBlurChange, true);
};
}, []);

useEffect(() => {
Expand Down Expand Up @@ -505,7 +513,6 @@ function Preview({
onMouseUp,
onMouseEnter,
onMouseLeave,
onContextMenu,
};

const resizableProps = useResizableProps({
Expand Down
Loading