[77] Zauberstab: Schraffur „Ohne“ (Muster none) nicht als Vorgabe

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-11-04 23:47:07 +00:00
1 parent a7a02c7b2d
commit 72c555afec
2 files changed
+17 -5

No files matched your search

+8
View File
@@ -46,6 +46,14 @@ describe("wandCommand", () => {
expect(wandCommand.options(s2)[0].value).toBe("Beton");
});
it("Schraffur „Ohne“ (Muster none) wird übersprungen", () => {
const p = project();
p.hatches = [{ id: "none", name: "Ohne", pattern: "none" } as unknown as Project["hatches"][number], ...p.hatches];
const [, r] = wandCommand.onInput(wandCommand.init(), { kind: "point", point: { x: 1, y: 1 } }, ctxOf(p));
const next = r.commit!(p);
expect(next.drawings2d[next.drawings2d.length - 1].hatchId).toBe("h1");
});
it("Klick ausserhalb: kein Commit, Befehl bleibt aktiv", () => {
const p = project();
const [, r] = wandCommand.onInput(wandCommand.init(), { kind: "point", point: { x: 9, y: 9 } }, ctxOf(p));
+9 -5
View File
@@ -7,16 +7,19 @@ import type { CmdOption, Command, CommandContext, CommandResult, CommandState, V
import { createMutation, createPreview } from "../createCore";
interface WandState extends CommandState {
/** `hatch`: Index in `project.hatches` (`NONE` = nur Umriss); `name`: Anzeige in der Befehlszeile. */
/** `hatch`: Index in den wählbaren Schraffuren (`NONE` = nur Umriss); `name`: Anzeige in der Befehlszeile. */
sticky: { hatch: number; name?: string };
}
const NONE = -1;
const idle = (): [CommandState, CommandResult] => [{ phase: "point", lastPoint: null }, { draft: null, done: true }];
/** Gewählte Schraffur: Index in `project.hatches`, `NONE` = nur Umriss; ausser Reichweite → erste. */
/** Wählbare Schraffuren: ohne Muster „none" (die Standard-Schraffur „Ohne" stünde sonst als Vorgabe vorne). */
const usable = (ctx: CommandContext) => ctx.project.hatches.filter((h) => h.pattern !== "none");
/** Gewählte Schraffur: Index in `usable`, `NONE` = nur Umriss; ausser Reichweite → erste. */
const hatchOf = (s: WandState, ctx: CommandContext): string | undefined =>
s.sticky.hatch === NONE ? undefined : (ctx.project.hatches[s.sticky.hatch] ?? ctx.project.hatches[0])?.id;
s.sticky.hatch === NONE ? undefined : (usable(ctx)[s.sticky.hatch] ?? usable(ctx)[0])?.id;
export const wandCommand: Command = {
name: "wand",
@@ -33,10 +36,11 @@ export const wandCommand: Command = {
onInput: (state, input, ctx): [CommandState, CommandResult] => {
const s = state as WandState;
if (input.kind === "option" && input.id === "hatch") {
const n = ctx.project.hatches.length;
const list = usable(ctx);
const n = list.length;
// Reihenfolge: 0, 1, …, n−1, keine, 0 …
const next = s.sticky.hatch === NONE ? 0 : s.sticky.hatch + 1 >= n ? NONE : s.sticky.hatch + 1;
return [{ ...s, sticky: { hatch: next, name: next === NONE ? undefined : ctx.project.hatches[next]?.name } } as WandState, { draft: null }];
return [{ ...s, sticky: { hatch: next, name: next === NONE ? undefined : list[next]?.name } } as WandState, { draft: null }];
}
if (input.kind !== "point") return [s, { draft: null }];
const at: Vec2 = input.point;