mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-25 06:22:14 -03:00
Prevent browser context menu on custom right-click menus
Always prevent the default browser context menu and stop event propagation on right-click interactions and custom menus. This ensures that only the application's custom context menus are shown and avoids interference from the browser's native context menu.
This commit is contained in:
@@ -90,9 +90,10 @@ export class CanvasInteractions {
|
|||||||
}
|
}
|
||||||
// 2. Inne przyciski myszy
|
// 2. Inne przyciski myszy
|
||||||
if (e.button === 2) { // Prawy przycisk myszy
|
if (e.button === 2) { // Prawy przycisk myszy
|
||||||
|
e.preventDefault(); // Always prevent right-click default behavior
|
||||||
|
e.stopPropagation(); // Stop event propagation
|
||||||
const clickedLayerResult = this.canvas.canvasLayers.getLayerAtPosition(worldCoords.x, worldCoords.y);
|
const clickedLayerResult = this.canvas.canvasLayers.getLayerAtPosition(worldCoords.x, worldCoords.y);
|
||||||
if (clickedLayerResult && this.canvas.canvasSelection.selectedLayers.includes(clickedLayerResult.layer)) {
|
if (clickedLayerResult && this.canvas.canvasSelection.selectedLayers.includes(clickedLayerResult.layer)) {
|
||||||
e.preventDefault();
|
|
||||||
this.canvas.canvasLayers.showBlendModeMenu(viewCoords.x, viewCoords.y);
|
this.canvas.canvasLayers.showBlendModeMenu(viewCoords.x, viewCoords.y);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -207,7 +208,9 @@ export class CanvasInteractions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleContextMenu(e) {
|
handleContextMenu(e) {
|
||||||
|
// Always prevent browser context menu - we handle all right-click interactions ourselves
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
handleWheel(e) {
|
handleWheel(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -639,6 +639,11 @@ export class CanvasLayers {
|
|||||||
container.appendChild(slider);
|
container.appendChild(slider);
|
||||||
content.appendChild(container);
|
content.appendChild(container);
|
||||||
});
|
});
|
||||||
|
// Add contextmenu event listener to the menu itself to prevent browser context menu
|
||||||
|
menu.addEventListener('contextmenu', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
const container = this.canvas.canvas.parentElement || document.body;
|
const container = this.canvas.canvas.parentElement || document.body;
|
||||||
container.appendChild(menu);
|
container.appendChild(menu);
|
||||||
const closeMenu = (e) => {
|
const closeMenu = (e) => {
|
||||||
|
|||||||
@@ -131,9 +131,11 @@ export class CanvasInteractions {
|
|||||||
|
|
||||||
// 2. Inne przyciski myszy
|
// 2. Inne przyciski myszy
|
||||||
if (e.button === 2) { // Prawy przycisk myszy
|
if (e.button === 2) { // Prawy przycisk myszy
|
||||||
|
e.preventDefault(); // Always prevent right-click default behavior
|
||||||
|
e.stopPropagation(); // Stop event propagation
|
||||||
|
|
||||||
const clickedLayerResult = this.canvas.canvasLayers.getLayerAtPosition(worldCoords.x, worldCoords.y);
|
const clickedLayerResult = this.canvas.canvasLayers.getLayerAtPosition(worldCoords.x, worldCoords.y);
|
||||||
if (clickedLayerResult && this.canvas.canvasSelection.selectedLayers.includes(clickedLayerResult.layer)) {
|
if (clickedLayerResult && this.canvas.canvasSelection.selectedLayers.includes(clickedLayerResult.layer)) {
|
||||||
e.preventDefault();
|
|
||||||
this.canvas.canvasLayers.showBlendModeMenu(viewCoords.x, viewCoords.y);
|
this.canvas.canvasLayers.showBlendModeMenu(viewCoords.x, viewCoords.y);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -263,7 +265,9 @@ export class CanvasInteractions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleContextMenu(e: MouseEvent): void {
|
handleContextMenu(e: MouseEvent): void {
|
||||||
|
// Always prevent browser context menu - we handle all right-click interactions ourselves
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleWheel(e: WheelEvent): void {
|
handleWheel(e: WheelEvent): void {
|
||||||
|
|||||||
@@ -739,6 +739,12 @@ export class CanvasLayers {
|
|||||||
content.appendChild(container);
|
content.appendChild(container);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add contextmenu event listener to the menu itself to prevent browser context menu
|
||||||
|
menu.addEventListener('contextmenu', (e: MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
|
||||||
const container = this.canvas.canvas.parentElement || document.body;
|
const container = this.canvas.canvas.parentElement || document.body;
|
||||||
container.appendChild(menu);
|
container.appendChild(menu);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user