diff --git a/view/canvas/brush.ts b/view/canvas/brush.ts index bba9000..36c58af 100644 --- a/view/canvas/brush.ts +++ b/view/canvas/brush.ts @@ -4,6 +4,7 @@ import type { Vec2D } from "@core/geometry"; import type { Layer } from "@core/layer"; import type { RasterLayer } from "@core/raster-layer"; import type { EditorState } from "@editor/state"; +import { isPanInteractionMode } from "@editor/tools"; import type { AppStore } from "@editor/store"; export type BrushSession = { @@ -13,7 +14,7 @@ export type BrushSession = { }; export function beginBrushSession(document: ImageDocument, editor: EditorState, point: Vec2D): BrushSession | undefined { - if (editor.tools.activeTool !== "brush" && editor.tools.activeTool !== "eraser") return undefined; + if (isPanInteractionMode(editor.tools.interactionMode) || (editor.tools.activeTool !== "brush" && editor.tools.activeTool !== "eraser")) return undefined; const layerId = editor.selection.layerIds[0]; if (!layerId) return undefined; const layer = findRasterLayer(document.artboards.flatMap((artboard) => artboard.layers), layerId); diff --git a/view/canvas/useCanvasInput.ts b/view/canvas/useCanvasInput.ts index 50d15af..c11d866 100644 --- a/view/canvas/useCanvasInput.ts +++ b/view/canvas/useCanvasInput.ts @@ -62,16 +62,6 @@ export function useCanvasInput( const handlePointerDown = (event: PointerEvent) => { const inputEvent = pointerInputEventFromPointerEvent(event); - const state = store.getState(); - const brush = beginBrushSession(state.document, state.editor, viewportPointToDocumentPoint(inputEvent.position, state.editor.viewport)); - if (brush) { - brushSessionId.current += 1; - brushSession.current = brush; - canvas.setPointerCapture(event.pointerId); - event.preventDefault(); - return; - } - const transformed = transformHandler.pointerDown(inputEvent); if (transformed) { canvas.setPointerCapture(event.pointerId); @@ -87,6 +77,18 @@ export function useCanvasInput( return; } + const state = store.getState(); + const brush = (inputEvent.buttons & 1) === 1 && !isPanInteractionMode(state.editor.tools.interactionMode) + ? beginBrushSession(state.document, state.editor, viewportPointToDocumentPoint(inputEvent.position, state.editor.viewport)) + : undefined; + if (brush) { + brushSessionId.current += 1; + brushSession.current = brush; + canvas.setPointerCapture(event.pointerId); + event.preventDefault(); + return; + } + const currentState = store.getState(); const selectionToolActive = currentState.editor.tools.activeTool === "select" || currentState.editor.tools.activeTool === "crop"; const selected = selectionToolActive && handleArtboardSelection({ @@ -101,6 +103,13 @@ export function useCanvasInput( const handlePointerMove = (event: PointerEvent) => { const inputEvent = pointerInputEventFromPointerEvent(event); if (brushSession.current) { + if ((inputEvent.buttons & 1) !== 1 || isPanInteractionMode(store.getState().editor.tools.interactionMode)) { + brushSessionId.current += 1; + brushSession.current = undefined; + event.preventDefault(); + return; + } + const activeSessionId = brushSessionId.current; const point = viewportPointToDocumentPoint(inputEvent.position, store.getState().editor.viewport); const settings = store.getState().editor.tools.brush;