Fix bug where handles are identical (#548)

This commit is contained in:
Steve Ruiz 2022-01-31 14:58:38 +00:00 committed by GitHub
parent 16076dcdac
commit 53cd70d0cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 24 deletions

View file

@ -123,7 +123,6 @@ export class ArrowSession extends BaseSession {
}) })
// If the handle changed produced no change, bail here // If the handle changed produced no change, bail here
if (!handleChange) return if (!handleChange) return
// If nothing changes, we want these to be the same object reference as // If nothing changes, we want these to be the same object reference as
// before. If it does change, we'll redefine this later on. And if we've // before. If it does change, we'll redefine this later on. And if we've
// made it this far, the shape should be a new object reference that // made it this far, the shape should be a new object reference that
@ -258,7 +257,7 @@ export class ArrowSession extends BaseSession {
pages: { pages: {
[this.app.currentPageId]: { [this.app.currentPageId]: {
shapes: { shapes: {
[shape.id]: Utils.deepMerge(next.shape, change ?? {}), [shape.id]: { ...next.shape, ...(change ?? {}) },
}, },
bindings: next.bindings, bindings: next.bindings,
}, },

View file

@ -2,27 +2,14 @@ import * as React from 'react'
import { Utils, TLBounds, SVGContainer } from '@tldraw/core' import { Utils, TLBounds, SVGContainer } from '@tldraw/core'
import { Vec } from '@tldraw/vec' import { Vec } from '@tldraw/vec'
import { defaultStyle } from '../shared/shape-styles' import { defaultStyle } from '../shared/shape-styles'
import { import { ArrowShape, TransformInfo, Decoration, TDShapeType, DashStyle, TDMeta } from '~types'
ArrowShape,
TransformInfo,
Decoration,
TDShapeType,
TDShape,
EllipseShape,
TDBinding,
DashStyle,
TDMeta,
} from '~types'
import { TDShapeUtil } from '../TDShapeUtil' import { TDShapeUtil } from '../TDShapeUtil'
import { import {
intersectArcBounds, intersectArcBounds,
intersectLineSegmentBounds, intersectLineSegmentBounds,
intersectLineSegmentLineSegment, intersectLineSegmentLineSegment,
intersectRayBounds,
intersectRayEllipse,
intersectRayLineSegment,
} from '@tldraw/intersect' } from '@tldraw/intersect'
import { BINDING_DISTANCE, GHOSTED_OPACITY } from '~constants' import { GHOSTED_OPACITY } from '~constants'
import { import {
getArcLength, getArcLength,
getArcPoints, getArcPoints,
@ -31,14 +18,12 @@ import {
getCtp, getCtp,
isAngleBetween, isAngleBetween,
} from './arrowHelpers' } from './arrowHelpers'
import { getTrianglePoints } from '../TriangleUtil/triangleHelpers'
import { styled } from '~styles' import { styled } from '~styles'
import { TextLabel, getFontStyle, getShapeStyle } from '../shared' import { TextLabel, getFontStyle, getShapeStyle } from '../shared'
import { getTextLabelSize } from '../shared/getTextSize' import { getTextLabelSize } from '../shared/getTextSize'
import { StraightArrow } from './components/StraightArrow' import { StraightArrow } from './components/StraightArrow'
import { CurvedArrow } from './components/CurvedArrow.tsx' import { CurvedArrow } from './components/CurvedArrow.tsx'
import { LabelMask } from '../shared/LabelMask' import { LabelMask } from '../shared/LabelMask'
import { TLDR } from '~state/TLDR'
type T = ArrowShape type T = ArrowShape
type E = HTMLDivElement type E = HTMLDivElement
@ -417,17 +402,16 @@ export class ArrowUtil extends TDShapeUtil<T, E> {
onHandleChange = (shape: T, handles: Partial<T['handles']>): Partial<T> | void => { onHandleChange = (shape: T, handles: Partial<T['handles']>): Partial<T> | void => {
let nextHandles = Utils.deepMerge<ArrowShape['handles']>(shape.handles, handles) let nextHandles = Utils.deepMerge<ArrowShape['handles']>(shape.handles, handles)
let nextBend = shape.bend let nextBend = shape.bend
nextHandles = { nextHandles = Utils.deepMerge(nextHandles, {
...nextHandles,
start: { start: {
...nextHandles.start,
point: Vec.toFixed(nextHandles.start.point), point: Vec.toFixed(nextHandles.start.point),
}, },
end: { end: {
...nextHandles.end,
point: Vec.toFixed(nextHandles.end.point), point: Vec.toFixed(nextHandles.end.point),
}, },
} })
// This will produce NaN values
if (Vec.isEqual(nextHandles.start.point, nextHandles.end.point)) return
// If the user is moving the bend handle, we want to move the bend point // If the user is moving the bend handle, we want to move the bend point
if ('bend' in handles) { if ('bend' in handles) {
const { start, end, bend } = nextHandles const { start, end, bend } = nextHandles