@@ -85,11 +85,6 @@ import type {
8585 PointsPositionUpdates ,
8686} from "./types" ;
8787
88- const editorMidPointsCache : {
89- version : number | null ;
90- points : ( GlobalPoint | null ) [ ] ;
91- zoom : number | null ;
92- } = { version : null , points : [ ] , zoom : null } ;
9388export class LinearElementEditor {
9489 public readonly elementId : ExcalidrawElement [ "id" ] & {
9590 _brand : "excalidrawLinearElementId" ;
@@ -536,7 +531,7 @@ export class LinearElementEditor {
536531 element : NonDeleted < ExcalidrawLinearElement > ,
537532 elementsMap : ElementsMap ,
538533 appState : InteractiveCanvasAppState ,
539- ) : typeof editorMidPointsCache [ "points" ] => {
534+ ) : ( GlobalPoint | null ) [ ] => {
540535 const boundText = getBoundTextElement ( element , elementsMap ) ;
541536
542537 // Since its not needed outside editor unless 2 pointer lines or bound text
@@ -548,25 +543,7 @@ export class LinearElementEditor {
548543 ) {
549544 return [ ] ;
550545 }
551- if (
552- editorMidPointsCache . version === element . version &&
553- editorMidPointsCache . zoom === appState . zoom . value
554- ) {
555- return editorMidPointsCache . points ;
556- }
557- LinearElementEditor . updateEditorMidPointsCache (
558- element ,
559- elementsMap ,
560- appState ,
561- ) ;
562- return editorMidPointsCache . points ! ;
563- } ;
564546
565- static updateEditorMidPointsCache = (
566- element : NonDeleted < ExcalidrawLinearElement > ,
567- elementsMap : ElementsMap ,
568- appState : InteractiveCanvasAppState ,
569- ) => {
570547 const points = LinearElementEditor . getPointsGlobalCoordinates (
571548 element ,
572549 elementsMap ,
@@ -598,9 +575,8 @@ export class LinearElementEditor {
598575 midpoints . push ( segmentMidPoint ) ;
599576 index ++ ;
600577 }
601- editorMidPointsCache . points = midpoints ;
602- editorMidPointsCache . version = element . version ;
603- editorMidPointsCache . zoom = appState . zoom . value ;
578+
579+ return midpoints ;
604580 } ;
605581
606582 static getSegmentMidpointHitCoords = (
@@ -654,8 +630,11 @@ export class LinearElementEditor {
654630 }
655631 }
656632 let index = 0 ;
657- const midPoints : typeof editorMidPointsCache [ "points" ] =
658- LinearElementEditor . getEditorMidPoints ( element , elementsMap , appState ) ;
633+ const midPoints = LinearElementEditor . getEditorMidPoints (
634+ element ,
635+ elementsMap ,
636+ appState ,
637+ ) ;
659638
660639 while ( index < midPoints . length ) {
661640 if ( midPoints [ index ] !== null ) {
@@ -1611,23 +1590,14 @@ export class LinearElementEditor {
16111590 y = midPoint [ 1 ] - boundTextElement . height / 2 ;
16121591 } else {
16131592 const index = element . points . length / 2 - 1 ;
1593+ const midSegmentMidpoint = LinearElementEditor . getSegmentMidPoint (
1594+ element ,
1595+ points [ index ] ,
1596+ points [ index + 1 ] ,
1597+ index + 1 ,
1598+ elementsMap ,
1599+ ) ;
16141600
1615- let midSegmentMidpoint = editorMidPointsCache . points [ index ] ;
1616- if ( element . points . length === 2 ) {
1617- midSegmentMidpoint = pointCenter ( points [ 0 ] , points [ 1 ] ) ;
1618- }
1619- if (
1620- ! midSegmentMidpoint ||
1621- editorMidPointsCache . version !== element . version
1622- ) {
1623- midSegmentMidpoint = LinearElementEditor . getSegmentMidPoint (
1624- element ,
1625- points [ index ] ,
1626- points [ index + 1 ] ,
1627- index + 1 ,
1628- elementsMap ,
1629- ) ;
1630- }
16311601 x = midSegmentMidpoint [ 0 ] - boundTextElement . width / 2 ;
16321602 y = midSegmentMidpoint [ 1 ] - boundTextElement . height / 2 ;
16331603 }
0 commit comments