From c28440b87801744a155dcae1f2d6ca8ef14547e3 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Mon, 30 Aug 2021 19:17:46 +0100 Subject: [PATCH] Move a few more strings to enums --- packages/tldraw/src/state/tlstate.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/tldraw/src/state/tlstate.ts b/packages/tldraw/src/state/tlstate.ts index af9103992..6f46baa3f 100644 --- a/packages/tldraw/src/state/tlstate.ts +++ b/packages/tldraw/src/state/tlstate.ts @@ -1156,7 +1156,7 @@ export class TLDrawState extends StateManager { ) } - startTextSession = (id?: string): this => { + startTextSession = (id: string): this => { return this.startSession(new Sessions.TextSession(this.state, id)) } @@ -1350,7 +1350,7 @@ export class TLDrawState extends StateManager { return this.startHandleSession(pagePoint, 'end', `create_${activeTool}`) } case TLDrawToolType.Text: { - return this.startTextSession() + return this.startTextSession(id) } case TLDrawToolType.Point: { break @@ -1499,24 +1499,34 @@ export class TLDrawState extends StateManager { this.updateOnPointerMove(info) } - // Pointer Events + /* ----------------- Pointer Events ----------------- */ + + onPointerMove: TLPointerEventHandler = (info) => { + // Several events (e.g. pan) can trigger the same "pointer move" behavior + this.updateOnPointerMove(info) + } + onPointerDown: TLPointerEventHandler = (info) => { switch (this.appState.status.current) { case TLDrawStatus.Idle: { switch (this.appState.activeTool) { - case 'draw': { + case TLDrawShapeType.Draw: { this.createActiveToolShape(info.point) break } - case 'rectangle': { + case TLDrawShapeType.Rectangle: { this.createActiveToolShape(info.point) break } - case 'ellipse': { + case TLDrawShapeType.Ellipse: { this.createActiveToolShape(info.point) break } - case 'arrow': { + case TLDrawShapeType.Arrow: { + this.createActiveToolShape(info.point) + break + } + case TLDrawShapeType.Text: { this.createActiveToolShape(info.point) break } @@ -1525,10 +1535,6 @@ export class TLDrawState extends StateManager { } } - onPointerMove: TLPointerEventHandler = (info) => { - this.updateOnPointerMove(info) - } - onPointerUp: TLPointerEventHandler = (info) => { switch (this.appState.status.current) { case TLDrawStatus.PointingBounds: {