Enhance path point deletion to correctly manage and reattach spline corridor junctions

This commit is contained in:
2026-05-13 20:04:13 +02:00
parent b948579be9
commit b7cf45a0b5

View File

@@ -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) {