From 2dff65da9ccfd4595ec3e8fd3fb7a9ab81b91646 Mon Sep 17 00:00:00 2001 From: Filip131311 Date: Thu, 10 Oct 2024 22:20:32 +0200 Subject: [PATCH 1/3] init --- .../src/webview/components/Preview.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/vscode-extension/src/webview/components/Preview.tsx b/packages/vscode-extension/src/webview/components/Preview.tsx index 2896444f2..24125ca1d 100644 --- a/packages/vscode-extension/src/webview/components/Preview.tsx +++ b/packages/vscode-extension/src/webview/components/Preview.tsx @@ -413,11 +413,16 @@ function Preview({ } } - function onContextMenu(e: MouseEvent) { - 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 + // 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); @@ -426,7 +431,10 @@ function Preview({ } } addEventListener("blur", onBlurChange, true); - return () => removeEventListener("blur", onBlurChange, true); + return () => { + window.removeEventListener("contextmenu", onContextMenu); + removeEventListener("blur", onBlurChange, true); + }; }, []); useEffect(() => { @@ -505,7 +513,6 @@ function Preview({ onMouseUp, onMouseEnter, onMouseLeave, - onContextMenu, }; const resizableProps = useResizableProps({ From b50acf5d7f465c35a1c927196ea75146ed6ca160 Mon Sep 17 00:00:00 2001 From: filip131311 <159789821+filip131311@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:28:19 +0200 Subject: [PATCH 2/3] Update packages/vscode-extension/src/webview/components/Preview.tsx --- packages/vscode-extension/src/webview/components/Preview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-extension/src/webview/components/Preview.tsx b/packages/vscode-extension/src/webview/components/Preview.tsx index 24125ca1d..31701cbd1 100644 --- a/packages/vscode-extension/src/webview/components/Preview.tsx +++ b/packages/vscode-extension/src/webview/components/Preview.tsx @@ -415,7 +415,7 @@ function Preview({ 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 + // 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) { e.stopImmediatePropagation(); From 76491e0b20555c01336225b0fba6addd47dcec2b Mon Sep 17 00:00:00 2001 From: filip131311 Date: Fri, 11 Oct 2024 15:44:16 +0200 Subject: [PATCH 3/3] changes after CR --- .../vscode-extension/src/webview/components/Preview.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vscode-extension/src/webview/components/Preview.tsx b/packages/vscode-extension/src/webview/components/Preview.tsx index 31701cbd1..fbb3874b5 100644 --- a/packages/vscode-extension/src/webview/components/Preview.tsx +++ b/packages/vscode-extension/src/webview/components/Preview.tsx @@ -417,7 +417,7 @@ function Preview({ // 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) { + function onContextMenu(e: any) { e.stopImmediatePropagation(); } @@ -430,10 +430,10 @@ function Preview({ setIsPressing(false); } } - addEventListener("blur", onBlurChange, true); + document.addEventListener("blur", onBlurChange, true); return () => { window.removeEventListener("contextmenu", onContextMenu); - removeEventListener("blur", onBlurChange, true); + document.removeEventListener("blur", onBlurChange, true); }; }, []);