From 9b5715623ac47a6919a3687481cfd6e974e23eee Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Fri, 26 Aug 2022 14:14:01 +0530 Subject: [PATCH] don't update points unitil deselected --- src/actions/actionFinalize.tsx | 4 ++++ src/components/App.tsx | 2 ++ src/element/linearElementEditor.ts | 20 ++++++++++++------- src/renderer/renderScene.ts | 17 ++++++++-------- .../regressionTests.test.tsx.snap | 16 +++++++++++++++ 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/actions/actionFinalize.tsx b/src/actions/actionFinalize.tsx index 2e78a1a37..370c60978 100644 --- a/src/actions/actionFinalize.tsx +++ b/src/actions/actionFinalize.tsx @@ -33,6 +33,9 @@ export const actionFinalize = register({ endBindingElement, ); } + const selectedLinearElement = appState.selectedLinearElement + ? new LinearElementEditor(element, scene) + : null; return { elements: element.points.length < 2 || isInvisiblySmallElement(element) @@ -42,6 +45,7 @@ export const actionFinalize = register({ ...appState, cursorButton: "up", editingLinearElement: null, + selectedLinearElement, }, commitToHistory: true, }; diff --git a/src/components/App.tsx b/src/components/App.tsx index 91a6cbe7f..23132eb68 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1907,6 +1907,7 @@ class App extends React.Component { editingLinearElement: new LinearElementEditor( selectedElements[0], this.scene, + true, ), }); } @@ -2485,6 +2486,7 @@ class App extends React.Component { editingLinearElement: new LinearElementEditor( selectedElements[0], this.scene, + true, ), }); } diff --git a/src/element/linearElementEditor.ts b/src/element/linearElementEditor.ts index 1cae4ad45..65d15df89 100644 --- a/src/element/linearElementEditor.ts +++ b/src/element/linearElementEditor.ts @@ -53,8 +53,12 @@ export class LinearElementEditor { public readonly endBindingElement: ExcalidrawBindableElement | null | "keep"; public readonly hoverPointIndex: number; public readonly midPointHovered: boolean; - - constructor(element: NonDeleted, scene: Scene) { + public readonly visiblePointIndexes: readonly number[]; + constructor( + element: NonDeleted, + scene: Scene, + editingLinearElement = false, + ) { this.elementId = element.id as string & { _brand: "excalidrawLinearElementId"; }; @@ -73,6 +77,10 @@ export class LinearElementEditor { }; this.hoverPointIndex = -1; this.midPointHovered = false; + this.visiblePointIndexes = LinearElementEditor.getVisiblePointIndexes( + element, + editingLinearElement, + ); } // --------------------------------------------------------------------------- @@ -410,11 +418,9 @@ export class LinearElementEditor { } static getVisiblePointIndexes( - linearElementEditor: LinearElementEditor, - appState: AppState, + element: NonDeleted, + editingLinearElement: boolean, ) { - const { elementId } = linearElementEditor; - const element = LinearElementEditor.getElement(elementId); if (!element) { return []; } @@ -432,7 +438,7 @@ export class LinearElementEditor { } const isExtremePoint = index === 0 || index === element.points.length - 1; if ( - appState.editingLinearElement || + editingLinearElement || isExtremePoint || distance >= 2 * LinearElementEditor.POINT_HANDLE_SIZE ) { diff --git a/src/renderer/renderScene.ts b/src/renderer/renderScene.ts index a5ba40368..ee15e96da 100644 --- a/src/renderer/renderScene.ts +++ b/src/renderer/renderScene.ts @@ -165,6 +165,9 @@ const renderSingleLinearPoint = ( isSelected: boolean, isPhantomPoint = false, ) => { + if (!point) { + return; + } context.strokeStyle = "#5e5ad8"; context.setLineDash([]); context.fillStyle = "rgba(255, 255, 255, 0.9)"; @@ -207,10 +210,9 @@ const renderLinearPointHandles = ( ? POINT_HANDLE_SIZE : POINT_HANDLE_SIZE / 2; - const visiblePointIndexes = LinearElementEditor.getVisiblePointIndexes( - appState.selectedLinearElement, - appState, - ); + const visiblePointIndexes = + appState.editingLinearElement?.visiblePointIndexes || + appState.selectedLinearElement.visiblePointIndexes; visiblePointIndexes.forEach((index) => { const isSelected = !!appState.editingLinearElement?.selectedPointsIndices?.includes(index); @@ -436,10 +438,9 @@ export const _renderScene = ({ appState.selectedLinearElement && appState.selectedLinearElement.hoverPointIndex >= 0 ) { - const visiblePointIndexes = LinearElementEditor.getVisiblePointIndexes( - appState.selectedLinearElement, - appState, - ); + const visiblePointIndexes = + appState.editingLinearElement?.visiblePointIndexes || + appState.selectedLinearElement.visiblePointIndexes; if ( visiblePointIndexes.includes( appState.selectedLinearElement.hoverPointIndex, diff --git a/src/tests/__snapshots__/regressionTests.test.tsx.snap b/src/tests/__snapshots__/regressionTests.test.tsx.snap index 3f023df45..42ebbaae5 100644 --- a/src/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/src/tests/__snapshots__/regressionTests.test.tsx.snap @@ -10993,6 +10993,10 @@ Object { }, "selectedPointsIndices": null, "startBindingElement": "keep", + "visiblePointIndexes": Array [ + 0, + 1, + ], }, "selectionElement": null, "shouldCacheIgnoreZoom": false, @@ -11219,6 +11223,10 @@ Object { }, "selectedPointsIndices": null, "startBindingElement": "keep", + "visiblePointIndexes": Array [ + 0, + 1, + ], }, "selectionElement": null, "shouldCacheIgnoreZoom": false, @@ -11672,6 +11680,10 @@ Object { }, "selectedPointsIndices": null, "startBindingElement": "keep", + "visiblePointIndexes": Array [ + 0, + 1, + ], }, "selectionElement": null, "shouldCacheIgnoreZoom": false, @@ -12077,6 +12089,10 @@ Object { }, "selectedPointsIndices": null, "startBindingElement": "keep", + "visiblePointIndexes": Array [ + 0, + 1, + ], }, "selectionElement": null, "shouldCacheIgnoreZoom": false,