Browse Source

fix: stale editing state

Peng Xiao 3 years ago
parent
commit
f45f0c2170

+ 1 - 1
tldraw/apps/tldraw-logseq/src/lib/tools/LogseqPortalTool/states/CreatingState.tsx

@@ -59,13 +59,13 @@ export class CreatingState extends TLToolState<
 
   onExit = () => {
     if (!this.creatingShape) return
-    this.app.clearEditingShape()
     this.app.history.resume()
 
     if (this.creatingShape?.props.pageId) {
       this.app.setSelectedShapes([this.creatingShape.id])
     } else {
       this.app.deleteShapes([this.creatingShape.id])
+      this.app.clearEditingShape()
     }
   }
 }

+ 3 - 0
tldraw/packages/core/src/lib/TLApp/TLApp.ts

@@ -529,6 +529,9 @@ export class TLApp<
     } else {
       this.selectionRotation = 0
     }
+    if (shapes.length === 0) {
+      this.clearEditingShape()
+    }
     return this
   }
 

+ 3 - 3
tldraw/packages/core/src/lib/tools/TLSelectTool/states/EditingShapeState.ts

@@ -20,6 +20,9 @@ export class EditingShapeState<
   onExit = () => {
     this.app.persist()
     this.app.clearEditingShape()
+
+    // Blur all inputs when exit idle
+    document.querySelectorAll<HTMLElement>('input,textarea').forEach(el => el.blur())
   }
 
   onPointerDown: TLEvents<S>['pointer'] = info => {
@@ -51,9 +54,6 @@ export class EditingShapeState<
           e.stopPropagation()
           this.app.setSelectedShapes([this.editingShape])
           this.tool.transition('idle')
-
-          // Blur all inputs when exit idle
-          document.querySelectorAll<HTMLElement>('input,textarea').forEach(el => el.blur())
         })
         break
       }