Add set box brush name command and update scene document migration

This commit is contained in:
2026-03-31 04:22:46 +02:00
parent 0040bcde35
commit 07999f8038
4 changed files with 76 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
import { createOpaqueId } from "../core/ids";
import { normalizeBrushName } from "../document/brushes";
import { getBoxBrushOrThrow, replaceBrush } from "./brush-command-helpers";
import type { EditorCommand } from "./command";
interface SetBoxBrushNameCommandOptions {
brushId: string;
name: string | null;
}
export function createSetBoxBrushNameCommand(options: SetBoxBrushNameCommandOptions): EditorCommand {
const normalizedName = normalizeBrushName(options.name);
let previousName: string | undefined;
return {
id: createOpaqueId("command"),
label: normalizedName === undefined ? "Clear box brush name" : `Rename box brush to ${normalizedName}`,
execute(context) {
const currentDocument = context.getDocument();
const brush = getBoxBrushOrThrow(currentDocument, options.brushId);
if (previousName === undefined) {
previousName = brush.name;
}
context.setDocument(
replaceBrush(currentDocument, {
...brush,
name: normalizedName
})
);
},
undo(context) {
const currentDocument = context.getDocument();
const brush = getBoxBrushOrThrow(currentDocument, options.brushId);
context.setDocument(
replaceBrush(currentDocument, {
...brush,
name: previousName
})
);
}
};
}