瀏覽代碼

fix: edit shape not working properly

Peng Xiao 3 年之前
父節點
當前提交
1387dfcc43

+ 1 - 1
src/main/frontend/components/sidebar.cljs

@@ -267,7 +267,7 @@
          {:class "whiteboard"
           :title "Whiteboards"
           :href  (rfe/href :whiteboards)
-          :icon  "files"})]]
+          :icon  "artboard"})]]
 
       (favorites t)
 

+ 0 - 1
tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx

@@ -114,7 +114,6 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
   hideRotateHandle = true
   canChangeAspectRatio = true
   canFlip = true
-  canActivate = true
   canEdit = true
 
   constructor(props = {} as Partial<LogseqPortalShapeProps>) {

+ 0 - 2
tldraw/apps/tldraw-logseq/src/lib/shapes/YouTubeShape.tsx

@@ -35,8 +35,6 @@ export class YouTubeShape extends TLBoxShape<YouTubeShapeProps> {
 
   canEdit = true
 
-  canActivate = true
-
   ReactContextBar = observer(() => {
     const { embedId } = this.props
     const rInput = React.useRef<HTMLInputElement>(null)

+ 1 - 0
tldraw/apps/tldraw-logseq/src/lib/shapes/text/TextLabel.tsx

@@ -76,6 +76,7 @@ export const TextLabel = React.memo(function TextLabel({
 
   const handleBlur = React.useCallback(
     (e: React.FocusEvent<HTMLTextAreaElement>) => {
+      if (!isEditing) return
       e.currentTarget.setSelectionRange(0, 0)
       onBlur?.()
     },

+ 0 - 1
tldraw/packages/core/src/lib/shapes/TLShape/TLShape.tsx

@@ -103,7 +103,6 @@ export abstract class TLShape<P extends TLShapeProps = TLShapeProps, M = any> {
   canFlip: TLFlag = true
   canEdit: TLFlag = false
   canBind: TLFlag = false
-  canActivate: TLFlag = false
   
   @observable nonce = 0
 

+ 1 - 11
tldraw/packages/core/src/lib/tools/TLSelectTool/states/IdleState.ts

@@ -1,4 +1,4 @@
-import { TLShape, TLApp, TLSelectTool, TLToolState } from '~lib'
+import { TLShape, TLApp, TLSelectTool, TLToolState, TLBoxShape } from '~lib'
 import { TLEventMap, TLEvents, TLShortcut, TLTargetType } from '~types'
 import { PointUtils } from '~utils'
 
@@ -47,7 +47,6 @@ export class IdleState<
   onPointerDown: TLEvents<S>['pointer'] = (info, event) => {
     const {
       selectedShapes,
-      selectedShapesArray,
       inputs: { ctrlKey },
     } = this.app
 
@@ -57,15 +56,6 @@ export class IdleState<
       return
     }
 
-    if (selectedShapesArray.length === 1 && selectedShapesArray[0].canEdit) {
-      this.tool.transition('editingShape', {
-        type: TLTargetType.Shape,
-        shape: selectedShapesArray[0],
-        order: 0,
-      })
-      return
-    }
-
     switch (info.type) {
       case TLTargetType.Selection: {
         switch (info.handle) {

+ 0 - 16
tldraw/packages/core/src/lib/tools/TLSelectTool/states/PointingBoundsBackgroundState.ts

@@ -10,21 +10,8 @@ export class PointingBoundsBackgroundState<
 > extends TLToolState<S, K, R, P> {
   static id = 'pointingBoundsBackground'
 
-  private pointedSelectedShape?: S
-
   cursor = TLCursor.Move
 
-  onEnter = () => {
-    // If there is exactly a single shape
-    if (this.app.selectedShapes.size === 1) {
-      this.pointedSelectedShape = this.app.selectedShapesArray[0]
-    }
-  }
-
-  onExit = () => {
-    this.pointedSelectedShape = undefined
-  }
-
   onWheel: TLEvents<S>['wheel'] = (info, e) => {
     this.onPointerMove(info, e)
   }
@@ -37,9 +24,6 @@ export class PointingBoundsBackgroundState<
   }
 
   onPointerUp: TLEvents<S>['pointer'] = () => {
-    if (this.pointedSelectedShape?.canActivate) {
-      this.app.setEditingShape(this.pointedSelectedShape.id)
-    }
     this.app.setSelectedShapes([])
     this.tool.transition('idle')
   }

+ 14 - 2
tldraw/packages/core/src/lib/tools/TLSelectTool/states/PointingSelectedShapeState.ts

@@ -1,6 +1,6 @@
 import { Vec } from '@tldraw/vec'
-import { TLApp, TLSelectTool, TLToolState, TLShape } from '~lib'
-import type { TLEventMap, TLEvents, TLEventShapeInfo } from '~types'
+import { TLApp, TLSelectTool, TLToolState, TLShape, TLBoxShape } from '~lib'
+import { TLEventMap, TLEvents, TLEventShapeInfo, TLTargetType } from '~types'
 
 export class PointingSelectedShapeState<
   S extends TLShape,
@@ -33,12 +33,24 @@ export class PointingSelectedShapeState<
 
   onPointerUp: TLEvents<S>['pointer'] = () => {
     const { shiftKey } = this.app.inputs
+    const { selectedShapesArray } = this.app
     if (!this.pointedSelectedShape) throw Error('Expected a pointed selected shape')
     if (shiftKey) {
       const { selectedIds } = this.app
       const next = Array.from(selectedIds.values())
       next.splice(next.indexOf(this.pointedSelectedShape.id), 1)
       this.app.setSelectedShapes(next)
+    } else if (
+      selectedShapesArray.length === 1 &&
+      this.pointedSelectedShape.canEdit &&
+      this.pointedSelectedShape instanceof TLBoxShape
+    ) {
+      this.tool.transition('editingShape', {
+        shape: this.pointedSelectedShape,
+        order: 0,
+        type: TLTargetType.Shape,
+      })
+      return
     } else {
       this.app.setSelectedShapes([this.pointedSelectedShape.id])
     }