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 1 commit
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
19 changes: 13 additions & 6 deletions packages/vscode-extension/src/webview/components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,16 @@ 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 changes the bahaviour of context menu, so it might not be necessery
filip131311 marked this conversation as resolved.
Show resolved Hide resolved
// in the future https://github.com/microsoft/vscode/issues/225411
function onContextMenu(e) {
e.stopImmediatePropagation();
}

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

function onBlurChange() {
if (!document.hasFocus()) {
setIsPanning(false);
Expand All @@ -426,7 +431,10 @@ function Preview({
}
}
addEventListener("blur", onBlurChange, true);
return () => removeEventListener("blur", onBlurChange, true);
return () => {
window.removeEventListener("contextmenu", onContextMenu);
removeEventListener("blur", onBlurChange, true);
Copy link
Member

Choose a reason for hiding this comment

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

can we update removeEventListener here and also corresponding addEventLIstener call to specify whether it operates on document or window (or something else?)

};
}, []);

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

const resizableProps = useResizableProps({
Expand Down
Loading