diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 7a19eeee0..8d3249fa8 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -6712,11 +6712,13 @@ class App extends React.Component { public handleCanvasPanUsingWheelOrSpaceDrag = ( event: React.PointerEvent | MouseEvent, ): boolean => { + const isRightClickDragging = event.button === POINTER_BUTTON.SECONDARY; if ( !( gesture.pointers.size <= 1 && (event.button === POINTER_BUTTON.WHEEL || (event.button === POINTER_BUTTON.MAIN && isHoldingSpace) || + isRightClickDragging || isHandToolActive(this.state) || this.state.viewModeEnabled) ) @@ -6744,9 +6746,16 @@ class App extends React.Component { ? false : /Linux/.test(window.navigator.platform); - setCursor(this.interactiveCanvas, CURSOR_TYPE.GRABBING); + if (!isRightClickDragging) { + setCursor(this.interactiveCanvas, CURSOR_TYPE.GRABBING); + } let { clientX: lastX, clientY: lastY } = event; + let hasDragged = false; const onPointerMove = withBatchedUpdatesThrottled((event: PointerEvent) => { + if (isRightClickDragging && !hasDragged) { + setCursor(this.interactiveCanvas, CURSOR_TYPE.GRABBING); + } + hasDragged = true; const deltaX = lastX - event.clientX; const deltaY = lastY - event.clientY; lastX = event.clientX; @@ -6807,6 +6816,11 @@ class App extends React.Component { }); this.savePointer(event.clientX, event.clientY, "up"); window.removeEventListener(EVENT.POINTER_MOVE, onPointerMove); + if (!hasDragged && isRightClickDragging) { + this.handleCanvasContextMenu( + event as React.MouseEvent, + ); + } window.removeEventListener(EVENT.POINTER_UP, teardown); window.removeEventListener(EVENT.BLUR, teardown); onPointerMove.flush(); @@ -9835,7 +9849,7 @@ class App extends React.Component { }; /** updates image cache, refreshing updated elements and/or setting status - to error for images that fail during element creation */ + to error for images that fail during element creation */ private updateImageCache = async ( elements: readonly InitializedExcalidrawImageElement[], files = this.files, @@ -10211,6 +10225,10 @@ class App extends React.Component { return; } + if (isPanning) { + return; + } + const { x, y } = viewportCoordsToSceneCoords(event, this.state); const element = this.getElementAtPosition(x, y, { preferSelected: true, diff --git a/packages/excalidraw/locales/en.json b/packages/excalidraw/locales/en.json index bf99dd58d..f995ac3c8 100644 --- a/packages/excalidraw/locales/en.json +++ b/packages/excalidraw/locales/en.json @@ -319,7 +319,7 @@ }, "hints": { "dismissSearch": "Escape to dismiss search", - "canvasPanning": "To move canvas, hold mouse wheel or spacebar while dragging, or use the hand tool", + "canvasPanning": "To move canvas, hold mouse wheel or spacebar while dragging, drag with right click, or use the hand tool", "linearElement": "Click to start multiple points, drag for single line", "arrowTool": "Click to start multiple points, drag for single line. Press {{arrowShortcut}} again to change arrow type.", "freeDraw": "Click and drag, release when you're finished",