From b7cf45a0b53a0b3ddac36a26a990f8c711823ea4 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 20:04:13 +0200 Subject: [PATCH] Enhance path point deletion to correctly manage and reattach spline corridor junctions --- src/commands/delete-path-points-command.ts | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/commands/delete-path-points-command.ts b/src/commands/delete-path-points-command.ts index ac542b90..94a57062 100644 --- a/src/commands/delete-path-points-command.ts +++ b/src/commands/delete-path-points-command.ts @@ -7,8 +7,13 @@ import { MIN_SCENE_PATH_POINT_COUNT, type ScenePath } from "../document/paths"; +import type { SplineCorridorJunctionRegistry } from "../document/spline-corridor-junctions"; import type { EditorCommand } from "./command"; +import { + cloneSplineCorridorJunctionRegistry, + setScenePathAndReattachJunctions +} from "./path-junction-maintenance"; interface DeletePathPointsCommandOptions { pathId: string; @@ -37,6 +42,7 @@ export function createDeletePathPointsCommand( ): EditorCommand { const pointIds = [...new Set(options.pointIds)]; let previousPath: ScenePath | null = null; + let previousJunctions: SplineCorridorJunctionRegistry | null = null; let previousSelection: EditorSelection | null = null; let previousToolMode: ToolMode | null = null; @@ -85,19 +91,21 @@ export function createDeletePathPointsCommand( previousToolMode = context.getToolMode(); } + if (previousJunctions === null) { + previousJunctions = cloneSplineCorridorJunctionRegistry( + currentDocument.splineCorridorJunctions + ); + } + const pointIdSet = new Set(pointIds); const nextPath = cloneScenePath({ ...path, points: path.points.filter((point) => !pointIdSet.has(point.id)) }); - context.setDocument({ - ...currentDocument, - paths: { - ...currentDocument.paths, - [path.id]: nextPath - } - }); + context.setDocument( + setScenePathAndReattachJunctions(currentDocument, nextPath) + ); context.setSelection( createFallbackSelection(nextPath, Math.min(...deletedIndexes)) ); @@ -115,7 +123,11 @@ export function createDeletePathPointsCommand( paths: { ...currentDocument.paths, [previousPath.id]: cloneScenePath(previousPath) - } + }, + splineCorridorJunctions: + previousJunctions === null + ? currentDocument.splineCorridorJunctions + : cloneSplineCorridorJunctionRegistry(previousJunctions) }); if (previousSelection !== null) {