From 2706fcf3443a2937925ada3af9a18d34f193c921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bertalan=20K=C3=B6rmendy?= Date: Wed, 2 Oct 2024 14:56:14 +0200 Subject: [PATCH] Specify elements to rerender in reparent & move strategies (#6448) ## Description Fill out `StrategyApplicationResult.elementsToRerender` with the element path of the affected elements in some reparent, insert and drag strategies --- .../strategies/absolute-reparent-strategy.tsx | 6 +++--- .../convert-to-absolute-and-move-strategy.tsx | 5 +---- .../strategies/drag-to-insert-metastrategy.tsx | 5 +---- .../strategies/draw-to-insert-metastrategy.tsx | 10 ++-------- .../strategies/draw-to-insert-text-strategy.tsx | 5 +---- .../strategies/reparent-helpers/reparent-helpers.ts | 7 +------ 6 files changed, 9 insertions(+), 29 deletions(-) diff --git a/editor/src/components/canvas/canvas-strategies/strategies/absolute-reparent-strategy.tsx b/editor/src/components/canvas/canvas-strategies/strategies/absolute-reparent-strategy.tsx index 0a448ca2b6c3..504a642b1f0d 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/absolute-reparent-strategy.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/absolute-reparent-strategy.tsx @@ -231,12 +231,12 @@ export function applyAbsoluteReparent( }, ) } else { - const moveCommands = + return ( absoluteMoveStrategy(canvasState, interactionSession, { ...defaultCustomStrategyState(), action: 'reparent', - })?.strategy.apply(strategyLifecycle).commands ?? [] - return strategyApplicationResult(moveCommands, 'rerender-all-elements') + })?.strategy.apply(strategyLifecycle) ?? emptyStrategyApplicationResult + ) } }, ) diff --git a/editor/src/components/canvas/canvas-strategies/strategies/convert-to-absolute-and-move-strategy.tsx b/editor/src/components/canvas/canvas-strategies/strategies/convert-to-absolute-and-move-strategy.tsx index 34695730d6b5..422708377163 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/convert-to-absolute-and-move-strategy.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/convert-to-absolute-and-move-strategy.tsx @@ -280,10 +280,7 @@ function convertToAbsoluteAndMoveStrategyFactory(setHuggingParentToFixed: SetHug return strategyApplicationResult( [...absoluteMoveApplyResult.commands, strategyIndicatorCommand], - // FIXME: This was added as a default value in https://github.com/concrete-utopia/utopia/pull/6408 - // This was to maintain the existing behaviour, but it should be replaced with a more specific value - // appropriate to this particular case. - 'rerender-all-elements', + absoluteMoveApplyResult.elementsToRerender, ) } // Fallback for when the checks above are not satisfied. diff --git a/editor/src/components/canvas/canvas-strategies/strategies/drag-to-insert-metastrategy.tsx b/editor/src/components/canvas/canvas-strategies/strategies/drag-to-insert-metastrategy.tsx index 031162699ef6..fe2a11266c2a 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/drag-to-insert-metastrategy.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/drag-to-insert-metastrategy.tsx @@ -281,10 +281,7 @@ function dragToInsertStrategyFactory( reparentCommand, ...optionalWrappingCommand, ], - // FIXME: This was added as a default value in https://github.com/concrete-utopia/utopia/pull/6408 - // This was to maintain the existing behaviour, but it should be replaced with a more specific value - // appropriate to this particular case. - 'rerender-all-elements', + [targetParent.intendedParentPath], { strategyGeneratedUidsCache: { [insertionSubjects[0].uid]: maybeWrapperWithUid?.uid, diff --git a/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-metastrategy.tsx b/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-metastrategy.tsx index 0da5cf8ca11a..2897296e9680 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-metastrategy.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-metastrategy.tsx @@ -303,10 +303,7 @@ export function drawToInsertStrategyFactory( resizeCommand, ...optionalWrappingCommand, ], - // FIXME: This was added as a default value in https://github.com/concrete-utopia/utopia/pull/6408 - // This was to maintain the existing behaviour, but it should be replaced with a more specific value - // appropriate to this particular case. - 'rerender-all-elements', + [targetParent.intendedParentPath], { strategyGeneratedUidsCache: { [insertionSubject.uid]: maybeWrapperWithUid?.uid, @@ -352,10 +349,7 @@ export function drawToInsertStrategyFactory( return strategyApplicationResult( [insertionCommand.command, reparentCommand, ...optionalWrappingCommand], - // FIXME: This was added as a default value in https://github.com/concrete-utopia/utopia/pull/6408 - // This was to maintain the existing behaviour, but it should be replaced with a more specific value - // appropriate to this particular case. - 'rerender-all-elements', + [targetParent.intendedParentPath], { strategyGeneratedUidsCache: { [insertionSubject.uid]: maybeWrapperWithUid?.uid, diff --git a/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-text-strategy.tsx b/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-text-strategy.tsx index 81b24156f222..0a02ebe94b00 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-text-strategy.tsx +++ b/editor/src/components/canvas/canvas-strategies/strategies/draw-to-insert-text-strategy.tsx @@ -126,10 +126,7 @@ export const drawToInsertTextMetaStrategy: MetaCanvasStrategy = ( }, }), ], - // FIXME: This was added as a default value in https://github.com/concrete-utopia/utopia/pull/6408 - // This was to maintain the existing behaviour, but it should be replaced with a more specific value - // appropriate to this particular case. - 'rerender-all-elements', + [targetParent.intendedParentPath], ) } diff --git a/editor/src/components/canvas/canvas-strategies/strategies/reparent-helpers/reparent-helpers.ts b/editor/src/components/canvas/canvas-strategies/strategies/reparent-helpers/reparent-helpers.ts index 3f6b30158503..c9600a2094ca 100644 --- a/editor/src/components/canvas/canvas-strategies/strategies/reparent-helpers/reparent-helpers.ts +++ b/editor/src/components/canvas/canvas-strategies/strategies/reparent-helpers/reparent-helpers.ts @@ -249,12 +249,7 @@ export function ifAllowedToReparent( if (allowed) { return ifAllowed() } else { - return strategyApplicationResult( - [setCursorCommand(CSSCursor.NotPermitted)], - 'rerender-all-elements', - {}, - 'failure', - ) + return strategyApplicationResult([setCursorCommand(CSSCursor.NotPermitted)], [], {}, 'failure') } }