浏览代码

fix: text origin on create

Konstantinos Kaloutas 2 年之前
父节点
当前提交
b468f0dc07
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      tldraw/packages/core/src/lib/tools/TLTextTool/states/CreatingState.tsx

+ 4 - 1
tldraw/packages/core/src/lib/tools/TLTextTool/states/CreatingState.tsx

@@ -1,5 +1,6 @@
 import type { TLTextTool } from '../TLTextTool'
 import type { TLTextTool } from '../TLTextTool'
 import Vec from '@tldraw/vec'
 import Vec from '@tldraw/vec'
+import { GRID_SIZE } from '@tldraw/core'
 import type { TLBounds } from '@tldraw/intersect'
 import type { TLBounds } from '@tldraw/intersect'
 import { transaction } from 'mobx'
 import { transaction } from 'mobx'
 import { type TLEventMap, TLCursor, TLTargetType } from '../../../../types'
 import { type TLEventMap, TLCursor, TLTargetType } from '../../../../types'
@@ -43,8 +44,10 @@ export class CreatingState<
     this.creatingShape.setScaleLevel(this.app.settings.scaleLevel)
     this.creatingShape.setScaleLevel(this.app.settings.scaleLevel)
     transaction(() => {
     transaction(() => {
       this.app.currentPage.addShapes(shape as unknown as S)
       this.app.currentPage.addShapes(shape as unknown as S)
+      const point = this.app.settings.snapToGrid ? Vec.snap([...originPoint], GRID_SIZE) : originPoint
       const { bounds } = shape
       const { bounds } = shape
-      shape.update({ point: Vec.sub(originPoint, [bounds.width / 2, bounds.height / 2]) })
+      shape.update({
+        point: Vec.sub(point, [bounds.width / 2, bounds.height / 2]) })
       this.app.transition('select')
       this.app.transition('select')
       this.app.setSelectedShapes([shape as unknown as S])
       this.app.setSelectedShapes([shape as unknown as S])
       this.app.currentState.transition('editingShape', {
       this.app.currentState.transition('editingShape', {