This commit is contained in:
ColemanDunn 2025-03-26 04:57:30 +00:00 committed by GitHub
commit b0cc253634
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View file

@ -6449,7 +6449,7 @@ class App extends React.Component<AppProps, AppState> {
// we must exit before we set `cursorButton` state and `savePointer` // we must exit before we set `cursorButton` state and `savePointer`
// else it will send pointer state & laser pointer events in collab when // else it will send pointer state & laser pointer events in collab when
// panning // panning
if (this.handleCanvasPanUsingWheelOrSpaceDrag(event)) { if (this.handleCanvasPan(event)) {
return; return;
} }
@ -6772,14 +6772,16 @@ class App extends React.Component<AppProps, AppState> {
}; };
// Returns whether the event is a panning // Returns whether the event is a panning
public handleCanvasPanUsingWheelOrSpaceDrag = ( public handleCanvasPan = (
event: React.PointerEvent<HTMLElement> | MouseEvent, event: React.PointerEvent<HTMLElement> | MouseEvent,
): boolean => { ): boolean => {
const isRightClicked = event.button === POINTER_BUTTON.SECONDARY;
if ( if (
!( !(
gesture.pointers.size <= 1 && gesture.pointers.size <= 1 &&
(event.button === POINTER_BUTTON.WHEEL || (event.button === POINTER_BUTTON.WHEEL ||
(event.button === POINTER_BUTTON.MAIN && isHoldingSpace) || (event.button === POINTER_BUTTON.MAIN && isHoldingSpace) ||
isRightClicked ||
isHandToolActive(this.state) || isHandToolActive(this.state) ||
this.state.viewModeEnabled) this.state.viewModeEnabled)
) )
@ -6807,9 +6809,16 @@ class App extends React.Component<AppProps, AppState> {
? false ? false
: /Linux/.test(window.navigator.platform); : /Linux/.test(window.navigator.platform);
if (!isRightClicked) {
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRABBING); setCursor(this.interactiveCanvas, CURSOR_TYPE.GRABBING);
}
let { clientX: lastX, clientY: lastY } = event; let { clientX: lastX, clientY: lastY } = event;
let hasDragged = false;
const onPointerMove = withBatchedUpdatesThrottled((event: PointerEvent) => { const onPointerMove = withBatchedUpdatesThrottled((event: PointerEvent) => {
if (isRightClicked && !hasDragged) {
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRABBING);
}
hasDragged = true;
const deltaX = lastX - event.clientX; const deltaX = lastX - event.clientX;
const deltaY = lastY - event.clientY; const deltaY = lastY - event.clientY;
lastX = event.clientX; lastX = event.clientX;
@ -6873,6 +6882,11 @@ class App extends React.Component<AppProps, AppState> {
window.removeEventListener(EVENT.POINTER_UP, teardown); window.removeEventListener(EVENT.POINTER_UP, teardown);
window.removeEventListener(EVENT.BLUR, teardown); window.removeEventListener(EVENT.BLUR, teardown);
onPointerMove.flush(); onPointerMove.flush();
if (!hasDragged && isRightClicked) {
this.handleCanvasContextMenu(
event as React.MouseEvent<HTMLElement | HTMLCanvasElement>,
);
}
}), }),
); );
window.addEventListener(EVENT.BLUR, teardown); window.addEventListener(EVENT.BLUR, teardown);
@ -10335,6 +10349,10 @@ class App extends React.Component<AppProps, AppState> {
return; return;
} }
if (isPanning) {
return;
}
const { x, y } = viewportCoordsToSceneCoords(event, this.state); const { x, y } = viewportCoordsToSceneCoords(event, this.state);
const element = this.getElementAtPosition(x, y, { const element = this.getElementAtPosition(x, y, {
preferSelected: true, preferSelected: true,

View file

@ -648,7 +648,7 @@ export const textWysiwyg = ({
// trying to pan by clicking inside text area itself -> handle here // trying to pan by clicking inside text area itself -> handle here
if (target instanceof HTMLTextAreaElement) { if (target instanceof HTMLTextAreaElement) {
event.preventDefault(); event.preventDefault();
app.handleCanvasPanUsingWheelOrSpaceDrag(event); app.handleCanvasPan(event);
} }
temporarilyDisableSubmit(); temporarilyDisableSubmit();
return; return;

View file

@ -320,7 +320,7 @@
}, },
"hints": { "hints": {
"dismissSearch": "Escape to dismiss search", "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", "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.", "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", "freeDraw": "Click and drag, release when you're finished",