From b948579be994e970086ed8f50c8e5dfc296e6a94 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 20:03:41 +0200 Subject: [PATCH] Improve junction maintenance when deleting a path point by tracking and reattaching spline corridor junctions. --- src/commands/delete-path-point-command.ts | 31 +++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/commands/delete-path-point-command.ts b/src/commands/delete-path-point-command.ts index 28a134a8..873dbcf1 100644 --- a/src/commands/delete-path-point-command.ts +++ b/src/commands/delete-path-point-command.ts @@ -8,8 +8,13 @@ import { MIN_SCENE_PATH_POINT_COUNT, type ScenePathPoint } from "../document/paths"; +import type { SplineCorridorJunctionRegistry } from "../document/spline-corridor-junctions"; import type { EditorCommand } from "./command"; +import { + cloneSplineCorridorJunctionRegistry, + setScenePathAndReattachJunctions +} from "./path-junction-maintenance"; interface DeletePathPointCommandOptions { pathId: string; @@ -40,6 +45,7 @@ export function createDeletePathPointCommand( ): EditorCommand { let deletedPoint: ScenePathPoint | null = null; let deletedPointIndex: number | null = null; + let previousJunctions: SplineCorridorJunctionRegistry | null = null; let previousSelection: EditorSelection | null = null; let previousToolMode: ToolMode | null = null; @@ -82,20 +88,25 @@ export function createDeletePathPointCommand( previousToolMode = context.getToolMode(); } + if (previousJunctions === null) { + previousJunctions = cloneSplineCorridorJunctionRegistry( + currentDocument.splineCorridorJunctions + ); + } + const nextPoints = path.points.filter((point) => point.id !== options.pointId); const fallbackPoint = nextPoints[Math.min(pointIndex, nextPoints.length - 1)] ?? null; - context.setDocument({ - ...currentDocument, - paths: { - ...currentDocument.paths, - [path.id]: cloneScenePath({ + context.setDocument( + setScenePathAndReattachJunctions( + currentDocument, + cloneScenePath({ ...path, points: nextPoints }) - } - }); + ) + ); context.setSelection( fallbackPoint === null ? setSinglePathSelection(options.pathId) @@ -126,7 +137,11 @@ export function createDeletePathPointCommand( ...path, points: nextPoints }) - } + }, + splineCorridorJunctions: + previousJunctions === null + ? currentDocument.splineCorridorJunctions + : cloneSplineCorridorJunctionRegistry(previousJunctions) }); if (previousSelection !== null) {