fix: text origin on create

pull/9391/head^2
Konstantinos Kaloutas 2023-06-14 17:40:34 +03:00 committed by Gabriel Horner
parent d277031918
commit b468f0dc07
1 changed files with 4 additions and 1 deletions

View File

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