fix(brush): stop painting after pointer release

This commit is contained in:
syntaxbullet
2026-07-03 17:43:13 +02:00
parent c13a6f5917
commit e75f8bc0a7
2 changed files with 68 additions and 28 deletions

View File

@@ -30,6 +30,7 @@ export function useCanvasInput(
): CanvasInputState {
const [isPanning, setIsPanning] = useState(false);
const brushSession = useRef<BrushSession>();
const brushSessionId = useRef(0);
useEffect(() => {
const canvas = canvasRef.current;
@@ -64,6 +65,7 @@ export function useCanvasInput(
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();
@@ -99,9 +101,10 @@ export function useCanvasInput(
const handlePointerMove = (event: PointerEvent) => {
const inputEvent = pointerInputEventFromPointerEvent(event);
if (brushSession.current) {
const activeSessionId = brushSessionId.current;
const point = viewportPointToDocumentPoint(inputEvent.position, store.getState().editor.viewport);
void updateBrushSession({ store, session: brushSession.current, point }).then((nextSession) => {
brushSession.current = nextSession;
if (brushSessionId.current === activeSessionId) brushSession.current = nextSession;
});
event.preventDefault();
return;
@@ -120,6 +123,7 @@ export function useCanvasInput(
const handlePointerUp = (event: PointerEvent) => {
const inputEvent = pointerInputEventFromPointerEvent(event);
if (brushSession.current) {
brushSessionId.current += 1;
brushSession.current = undefined;
event.preventDefault();
return;