diff --git a/packages/core/src/hooks/useShapeTree.tsx b/packages/core/src/hooks/useShapeTree.tsx index 155f31ad5..8645b0d64 100644 --- a/packages/core/src/hooks/useShapeTree.tsx +++ b/packages/core/src/hooks/useShapeTree.tsx @@ -18,13 +18,13 @@ function addToShapeTree>( branch: IShapeTreeNode[], shapes: TLPage['shapes'], pageState: { - bindingTargetId?: string - bindingId?: string - hoveredId?: string + bindingTargetId?: string | null + bindingId?: string | null + hoveredId?: string | null selectedIds: string[] - currentParentId?: string - editingId?: string - editingBindingId?: string + currentParentId?: string | null + editingId?: string | null + editingBindingId?: string | null }, meta?: M ) { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 79efd67cf..1a3992d10 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -24,12 +24,12 @@ export interface TLPageState { zoom: number } brush?: TLBounds - pointedId?: string - hoveredId?: string - editingId?: string - bindingId?: string + pointedId?: string | null + hoveredId?: string | null + editingId?: string | null + bindingId?: string | null boundsRotation?: number - currentParentId?: string + currentParentId?: string | null } export interface TLHandle { diff --git a/packages/tldraw/src/state/session/sessions/text/text.session.ts b/packages/tldraw/src/state/session/sessions/text/text.session.ts index 75cb9ea7f..e5c958c96 100644 --- a/packages/tldraw/src/state/session/sessions/text/text.session.ts +++ b/packages/tldraw/src/state/session/sessions/text/text.session.ts @@ -146,7 +146,7 @@ export class TextSession implements Session { }, pageState: { [pageId]: { - editingId: undefined, + editingId: null, }, }, }, @@ -166,7 +166,7 @@ export class TextSession implements Session { }, pageState: { [pageId]: { - editingId: undefined, + editingId: null, selectedIds: [initialShape.id], }, }, diff --git a/packages/tldraw/src/state/tlstate.ts b/packages/tldraw/src/state/tlstate.ts index 655aaa610..102372d6b 100644 --- a/packages/tldraw/src/state/tlstate.ts +++ b/packages/tldraw/src/state/tlstate.ts @@ -408,6 +408,7 @@ export class TLDrawState extends StateManager { */ selectTool = (tool: TLDrawShapeType | 'select'): this => { if (this.session) return this + return this.patchState( { appState: { @@ -462,10 +463,10 @@ export class TLDrawState extends StateManager { document: { pageStates: { [this.currentPageId]: { - bindingId: undefined, - editingId: undefined, - hoveredId: undefined, - pointedId: undefined, + bindingId: null, + editingId: null, + hoveredId: null, + pointedId: null, }, }, }, @@ -1356,6 +1357,7 @@ export class TLDrawState extends StateManager { if (result === undefined) { this.isCreating = false + return this.patchState( { appState: { @@ -1391,24 +1393,9 @@ export class TLDrawState extends StateManager { pageStates: { [this.currentPageId]: { selectedIds: [], - editingId: undefined, - bindingId: undefined, - hoveredId: undefined, - }, - }, - }, - } - - // ...and set editingId back to undefined - result.after = { - ...result.after, - document: { - ...result.after.document, - pageStates: { - ...result.after.document?.pageStates, - [this.currentPageId]: { - ...(result.after.document?.pageStates || {})[this.currentPageId], - editingId: undefined, + editingId: null, + bindingId: null, + hoveredId: null, }, }, }, @@ -1431,6 +1418,17 @@ export class TLDrawState extends StateManager { }, } + result.after.document = { + ...result.after.document, + pageStates: { + ...result.after.document?.pageStates, + [this.currentPageId]: { + ...(result.after.document?.pageStates || {})[this.currentPageId], + editingId: null, + }, + }, + } + this.setState(result, `session:complete:${session.id}`) } else { this.patchState( @@ -1446,7 +1444,7 @@ export class TLDrawState extends StateManager { document: { pageStates: { [this.currentPageId]: { - editingId: undefined, + editingId: null, }, }, }, @@ -2400,6 +2398,9 @@ export class TLDrawState extends StateManager { } break } + case TLDrawStatus.EditingText: { + this.completeSession() + } } }