[84] Undo-Verlauf als Liste: Schritt-Beschriftungen im Kern, Sprung zu Schritt N, Panel "Verlauf"
This commit is contained in:
19 files changed
+668
-24
No files matched your search
+3
-2
@@ -1678,7 +1678,7 @@ export default function App() {
|
||||
.arrayBuffer()
|
||||
.then((buf) => readIfcFlat(new Uint8Array(buf), elements))
|
||||
.then((flat) => {
|
||||
const r = getState().commitImport((doc, base, now) => doc.importIfc(base, flat, { fileName: f.name, elements }, now));
|
||||
const r = getState().commitImport((doc, base, now) => doc.importIfc(base, flat, { fileName: f.name, elements }, now), "history.import.ifc");
|
||||
if (!r) return;
|
||||
const report = r.report;
|
||||
if (elements && r.summary) {
|
||||
@@ -3302,7 +3302,7 @@ export default function App() {
|
||||
notify={notify}
|
||||
onImport={(read, fileName, placement) => {
|
||||
// Der Kern macht die Kontext-Meshes und übernimmt sie als EINEN Undo-Schritt ([K4] S4).
|
||||
const r = getState().commitImport((doc, base, now) => doc.importMesh(base, read.flat, { fileName, placement }, now));
|
||||
const r = getState().commitImport((doc, base, now) => doc.importMesh(base, read.flat, { fileName, placement }, now), "history.import.mesh");
|
||||
if (!r) return;
|
||||
fitToContextObjects(addedItems(r.ops, "context") as ContextObject[]);
|
||||
notify(formatMeshReport(read.report, t), r.contextObjects === 0 || read.report.truncated ? "warning" : "info");
|
||||
@@ -3416,6 +3416,7 @@ export default function App() {
|
||||
onToggleResources={() => toggleResources()}
|
||||
onOpenSettings={() => openSettings()}
|
||||
onOpenBcf={() => setLayout((l) => revealPanel(l, "bcf"))}
|
||||
onOpenHistory={() => setLayout((l) => revealPanel(l, "history"))}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -441,6 +441,30 @@ export class ProjectDocument {
|
||||
return project;
|
||||
}
|
||||
|
||||
/** Springt im Verlauf auf Undo-Tiefe `target` (mehrere Schritte, ein Kern-Aufruf); `null` = schon dort/ausserhalb. */
|
||||
jumpTo(base: Project, target: number): Project | null {
|
||||
if (base !== this.mirror || !this.handle) {
|
||||
this.ensure(base);
|
||||
return null;
|
||||
}
|
||||
const json = core().doc_history_jump(this.handle, target);
|
||||
if (!json) return null;
|
||||
const project = applyOps(base, JSON.parse(json) as CoreOp[], core().doc_last_hits(this.handle));
|
||||
this.mirror = project;
|
||||
return project;
|
||||
}
|
||||
|
||||
/** Beschriftung (i18n-Schlüssel oder Text) für den nächsten neu angelegten Undo-Schritt; leer = keine. */
|
||||
setHistoryLabel(label: string): void {
|
||||
if (this.handle) core().doc_history_label(this.handle, label);
|
||||
}
|
||||
|
||||
/** Beschriftungen der Verlaufsschritte: Undo (ältester zuerst) und Redo (nächster zuerst). */
|
||||
historyLabels(): { undo: string[]; redo: string[] } {
|
||||
const json = this.handle ? core().doc_history_labels(this.handle) : "";
|
||||
return json ? (JSON.parse(json) as { undo: string[]; redo: string[] }) : { undo: [], redo: [] };
|
||||
}
|
||||
|
||||
/** Verlaufsstand: Undo-/Redo-Tiefe und geschätzter Speicher (Bytes). */
|
||||
historyState(): { undo: number; redo: number; bytes: number } {
|
||||
const s = this.handle ? core().doc_history_state(this.handle) : new Float64Array(0);
|
||||
|
||||
@@ -2553,6 +2553,102 @@ export const de = {
|
||||
"bcf.addViewpoint": "Ansicht aufnehmen",
|
||||
"bcf.addViewpoint.hint": "Hängt die aktuelle 3D-Kamera mit Bild und der Auswahl als Viewpoint an das Thema.",
|
||||
"bcf.noSnapshot": "Kein Bild aufgenommen (3D-Bild nicht lesbar); die Kamera ist trotzdem gespeichert.",
|
||||
"nav.history": "Verlauf",
|
||||
"history.empty": "Noch keine Änderungen.",
|
||||
"history.current": "Aktueller Stand",
|
||||
"history.start": "Ausgangsstand",
|
||||
"history.step.generic": "Änderung",
|
||||
"history.grip": "Griff ziehen",
|
||||
"history.import": "Import",
|
||||
"history.import.ifc": "Import IFC",
|
||||
"history.import.mesh": "Import 3D-Modell",
|
||||
"history.import.drawing": "Import Zeichnung",
|
||||
"history.op.add": "{what} hinzufügen",
|
||||
"history.op.replace": "{what} ändern",
|
||||
"history.op.remove": "{what} löschen",
|
||||
"history.op.reorder": "{what} umordnen",
|
||||
"history.op.setField": "{what} ändern",
|
||||
"history.cmd.arc": "Bogen",
|
||||
"history.cmd.autodim": "Automassketten",
|
||||
"history.cmd.bezier": "Bézierkurve",
|
||||
"history.cmd.block": "Block einfügen",
|
||||
"history.cmd.break": "Auftrennen",
|
||||
"history.cmd.ceiling": "Decke zeichnen",
|
||||
"history.cmd.ceilingOpening": "Deckenöffnung",
|
||||
"history.cmd.chamfer": "Fase",
|
||||
"history.cmd.circle": "Kreis zeichnen",
|
||||
"history.cmd.column": "Stütze zeichnen",
|
||||
"history.cmd.defblock": "Block definieren",
|
||||
"history.cmd.detailref": "Detailverweis",
|
||||
"history.cmd.dimension": "Bemassung",
|
||||
"history.cmd.ellipse": "Ellipse zeichnen",
|
||||
"history.cmd.explode": "Auflösen",
|
||||
"history.cmd.extend": "Verlängern",
|
||||
"history.cmd.extrude": "Extrusion",
|
||||
"history.cmd.fillet": "Verrundung",
|
||||
"history.cmd.join": "Verbinden",
|
||||
"history.cmd.kote": "Höhenkote",
|
||||
"history.cmd.leader": "Beschriftungspfeil",
|
||||
"history.cmd.line": "Linie zeichnen",
|
||||
"history.cmd.multiline": "Mehrfachlinie",
|
||||
"history.cmd.offset": "Versatz",
|
||||
"history.cmd.opening": "Öffnung setzen",
|
||||
"history.cmd.pointmarker": "Punktmarke",
|
||||
"history.cmd.polygon": "Polygon zeichnen",
|
||||
"history.cmd.polyline": "Polylinie zeichnen",
|
||||
"history.cmd.ray": "Strahl",
|
||||
"history.cmd.rect": "Rechteck zeichnen",
|
||||
"history.cmd.rect4": "Rechteck zeichnen",
|
||||
"history.cmd.revcloud": "Revisionswolke",
|
||||
"history.cmd.roof": "Dach zeichnen",
|
||||
"history.cmd.roofHole": "Dachöffnung",
|
||||
"history.cmd.room": "Raum zeichnen",
|
||||
"history.cmd.roomInside": "Raum aus Umriss",
|
||||
"history.cmd.scalebar": "Massstabsbalken",
|
||||
"history.cmd.sectionline": "Schnittlinie",
|
||||
"history.cmd.solid": "Körper",
|
||||
"history.cmd.solidOutline": "Körper aus Umriss",
|
||||
"history.cmd.solidbool": "Körper-Boolesche",
|
||||
"history.cmd.spline": "Spline zeichnen",
|
||||
"history.cmd.stair": "Treppe zeichnen",
|
||||
"history.cmd.terrain": "Gelände",
|
||||
"history.cmd.text": "Text setzen",
|
||||
"history.cmd.textbox": "Textfeld",
|
||||
"history.cmd.textpath": "Text auf Pfad",
|
||||
"history.cmd.transform": "Transformieren",
|
||||
"history.cmd.trim": "Stutzen",
|
||||
"history.cmd.voidbox": "Aussparung",
|
||||
"history.cmd.wall": "Wand zeichnen",
|
||||
"history.cmd.wipeout": "Abdeckfläche",
|
||||
"history.cmd.xline": "Hilfslinie",
|
||||
"history.cmd.align": "Ausrichten",
|
||||
"history.cmd.distribute": "Verteilen",
|
||||
"history.cmd.paste": "Einfügen",
|
||||
"history.cmd.split": "Teilen",
|
||||
"history.coll.walls": "Wand",
|
||||
"history.coll.ceilings": "Decke",
|
||||
"history.coll.roofs": "Dach",
|
||||
"history.coll.openings": "Öffnung",
|
||||
"history.coll.stairs": "Treppe",
|
||||
"history.coll.rooms": "Raum",
|
||||
"history.coll.drawings2d": "2D-Element",
|
||||
"history.coll.columns": "Stütze",
|
||||
"history.coll.extrudedSolids": "Körper",
|
||||
"history.coll.groups": "Gruppe",
|
||||
"history.coll.layers": "Ebene",
|
||||
"history.coll.drawingLevels": "Geschoss",
|
||||
"history.coll.pens": "Stift",
|
||||
"history.coll.hatches": "Schraffur",
|
||||
"history.coll.lineStyles": "Linienstil",
|
||||
"history.coll.textStyles": "Textstil",
|
||||
"history.coll.components": "Bauteilaufbau",
|
||||
"history.coll.wallTypes": "Wandtyp",
|
||||
"history.coll.layouts": "Layout",
|
||||
"history.coll.viewSnapshots": "Ausschnitt",
|
||||
"history.coll.context": "Kontext",
|
||||
"history.coll.penSets": "Stiftsatz",
|
||||
"history.coll.customPalettes": "Palette",
|
||||
"history.coll.blockDefs": "Blockdefinition",
|
||||
} as const;
|
||||
|
||||
export type TranslationKey = keyof typeof de;
|
||||
@@ -2539,4 +2539,100 @@ export const en: Record<TranslationKey, string> = {
|
||||
"bcf.addViewpoint": "Capture view",
|
||||
"bcf.addViewpoint.hint": "Attaches the current 3D camera with image and selection to the topic as a viewpoint.",
|
||||
"bcf.noSnapshot": "No image captured (3D image not readable); the camera is saved anyway.",
|
||||
"nav.history": "History",
|
||||
"history.empty": "No changes yet.",
|
||||
"history.current": "Current state",
|
||||
"history.start": "Initial state",
|
||||
"history.step.generic": "Change",
|
||||
"history.grip": "Drag handle",
|
||||
"history.import": "Import",
|
||||
"history.import.ifc": "Import IFC",
|
||||
"history.import.mesh": "Import 3D model",
|
||||
"history.import.drawing": "Import drawing",
|
||||
"history.op.add": "Add {what}",
|
||||
"history.op.replace": "Change {what}",
|
||||
"history.op.remove": "Delete {what}",
|
||||
"history.op.reorder": "Reorder {what}",
|
||||
"history.op.setField": "Change {what}",
|
||||
"history.cmd.arc": "Arc",
|
||||
"history.cmd.autodim": "Auto dimensions",
|
||||
"history.cmd.bezier": "Bezier curve",
|
||||
"history.cmd.block": "Insert block",
|
||||
"history.cmd.break": "Break",
|
||||
"history.cmd.ceiling": "Draw ceiling",
|
||||
"history.cmd.ceilingOpening": "Ceiling opening",
|
||||
"history.cmd.chamfer": "Chamfer",
|
||||
"history.cmd.circle": "Draw circle",
|
||||
"history.cmd.column": "Draw column",
|
||||
"history.cmd.defblock": "Define block",
|
||||
"history.cmd.detailref": "Detail reference",
|
||||
"history.cmd.dimension": "Dimension",
|
||||
"history.cmd.ellipse": "Draw ellipse",
|
||||
"history.cmd.explode": "Explode",
|
||||
"history.cmd.extend": "Extend",
|
||||
"history.cmd.extrude": "Extrude",
|
||||
"history.cmd.fillet": "Fillet",
|
||||
"history.cmd.join": "Join",
|
||||
"history.cmd.kote": "Level mark",
|
||||
"history.cmd.leader": "Leader",
|
||||
"history.cmd.line": "Draw line",
|
||||
"history.cmd.multiline": "Multiline",
|
||||
"history.cmd.offset": "Offset",
|
||||
"history.cmd.opening": "Place opening",
|
||||
"history.cmd.pointmarker": "Point marker",
|
||||
"history.cmd.polygon": "Draw polygon",
|
||||
"history.cmd.polyline": "Draw polyline",
|
||||
"history.cmd.ray": "Ray",
|
||||
"history.cmd.rect": "Draw rectangle",
|
||||
"history.cmd.rect4": "Draw rectangle",
|
||||
"history.cmd.revcloud": "Revision cloud",
|
||||
"history.cmd.roof": "Draw roof",
|
||||
"history.cmd.roofHole": "Roof opening",
|
||||
"history.cmd.room": "Draw room",
|
||||
"history.cmd.roomInside": "Room from outline",
|
||||
"history.cmd.scalebar": "Scale bar",
|
||||
"history.cmd.sectionline": "Section line",
|
||||
"history.cmd.solid": "Solid",
|
||||
"history.cmd.solidOutline": "Solid from outline",
|
||||
"history.cmd.solidbool": "Solid boolean",
|
||||
"history.cmd.spline": "Draw spline",
|
||||
"history.cmd.stair": "Draw stair",
|
||||
"history.cmd.terrain": "Terrain",
|
||||
"history.cmd.text": "Place text",
|
||||
"history.cmd.textbox": "Text box",
|
||||
"history.cmd.textpath": "Text on path",
|
||||
"history.cmd.transform": "Transform",
|
||||
"history.cmd.trim": "Trim",
|
||||
"history.cmd.voidbox": "Void box",
|
||||
"history.cmd.wall": "Draw wall",
|
||||
"history.cmd.wipeout": "Wipeout",
|
||||
"history.cmd.xline": "Construction line",
|
||||
"history.cmd.align": "Align",
|
||||
"history.cmd.distribute": "Distribute",
|
||||
"history.cmd.paste": "Paste",
|
||||
"history.cmd.split": "Split",
|
||||
"history.coll.walls": "wall",
|
||||
"history.coll.ceilings": "ceiling",
|
||||
"history.coll.roofs": "roof",
|
||||
"history.coll.openings": "opening",
|
||||
"history.coll.stairs": "stair",
|
||||
"history.coll.rooms": "room",
|
||||
"history.coll.drawings2d": "2D element",
|
||||
"history.coll.columns": "column",
|
||||
"history.coll.extrudedSolids": "solid",
|
||||
"history.coll.groups": "group",
|
||||
"history.coll.layers": "layer",
|
||||
"history.coll.drawingLevels": "level",
|
||||
"history.coll.pens": "pen",
|
||||
"history.coll.hatches": "hatch",
|
||||
"history.coll.lineStyles": "line style",
|
||||
"history.coll.textStyles": "text style",
|
||||
"history.coll.components": "component",
|
||||
"history.coll.wallTypes": "wall type",
|
||||
"history.coll.layouts": "layout",
|
||||
"history.coll.viewSnapshots": "view snapshot",
|
||||
"history.coll.context": "context",
|
||||
"history.coll.penSets": "pen set",
|
||||
"history.coll.customPalettes": "palette",
|
||||
"history.coll.blockDefs": "block definition",
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
// Dock-Panel „Verlauf" ([84]): die Undo-Schritte als Liste, jüngster oben, der aktuelle Stand
|
||||
// markiert, Wiederholen-Schritte (noch nicht gültig) gedimmt darüber. Klick auf einen Eintrag springt
|
||||
// dorthin (`jumpHistory`: ein Kern-Aufruf über mehrere Schritte). Die Beschriftungen liefert der Kern
|
||||
// (`historyEntries`), Anzeigetext über `historyLabelText`.
|
||||
//
|
||||
// Bezeichner englisch, UI-Text/Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { useStore } from "../state/appStore";
|
||||
import { historyLabelText } from "../state/historyLabels";
|
||||
|
||||
interface Entry {
|
||||
/** Undo-Tiefe, auf die ein Klick springt (0 = Ausgangsstand). */
|
||||
depth: number;
|
||||
text: string;
|
||||
future: boolean;
|
||||
}
|
||||
|
||||
export function HistoryPanel() {
|
||||
const undoDepth = useStore((s) => s.undoDepth);
|
||||
const redoDepth = useStore((s) => s.redoDepth);
|
||||
const project = useStore((s) => s.project);
|
||||
const historyEntries = useStore((s) => s.historyEntries);
|
||||
const jumpHistory = useStore((s) => s.jumpHistory);
|
||||
|
||||
const entries = useMemo<Entry[]>(() => {
|
||||
const { undo, redo } = historyEntries();
|
||||
const list: Entry[] = [{ depth: 0, text: t("history.start"), future: false }];
|
||||
undo.forEach((l, i) => list.push({ depth: i + 1, text: historyLabelText(l), future: false }));
|
||||
redo.forEach((l, i) => list.push({ depth: undo.length + i + 1, text: historyLabelText(l), future: true }));
|
||||
return list.reverse();
|
||||
// `project` ändert sich mit jedem Schritt; die Tiefen fangen Sprünge ab.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [historyEntries, undoDepth, redoDepth, project]);
|
||||
|
||||
if (undoDepth + redoDepth === 0) {
|
||||
return (
|
||||
<section className="nav-group" data-testid="history-panel">
|
||||
<div className="nav-empty">{t("history.empty")}</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<section className="nav-group" data-testid="history-panel">
|
||||
<ul className="nav-list" role="listbox" aria-label={t("nav.history")} style={{ listStyle: "none", margin: 0, padding: 0 }}>
|
||||
{entries.map((e) => {
|
||||
const current = e.depth === undoDepth;
|
||||
return (
|
||||
<li
|
||||
key={e.depth}
|
||||
role="option"
|
||||
aria-selected={current}
|
||||
className={`history-row${current ? " active" : ""}${e.future ? " future" : ""}`}
|
||||
data-testid="history-entry"
|
||||
data-depth={e.depth}
|
||||
title={current ? t("history.current") : undefined}
|
||||
onClick={() => jumpHistory(e.depth)}
|
||||
>
|
||||
<span className="nav-label">{e.text}</span>
|
||||
{current && <span aria-hidden="true">◀</span>}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -98,6 +98,17 @@ export function RoomBalanceTabIcon() {
|
||||
);
|
||||
}
|
||||
|
||||
/** Verlauf — Uhr mit Rückwärtspfeil. */
|
||||
export function HistoryTabIcon() {
|
||||
return (
|
||||
<svg {...common}>
|
||||
<path d="M2.5 8a5.5 5.5 0 1 0 1.8-4.1" />
|
||||
<path d="M2.5 2.5v3h3" />
|
||||
<path d="M8 5v3.2l2 1.3" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/** BCF-Themen — Sprechblase mit Haken (Koordinations-Thema). */
|
||||
export function BcfTabIcon() {
|
||||
return (
|
||||
|
||||
@@ -26,6 +26,7 @@ import { ElementTreePanel, ElementsTabIcon } from "./ElementTreePanel";
|
||||
import { ViewSnapshotsPanel, ViewSnapshotsTabIcon } from "./ViewSnapshotsPanel";
|
||||
import { LayoutsPanel, LayoutsTabIcon } from "./LayoutsPanel";
|
||||
import { BcfPanel } from "./BcfPanel";
|
||||
import { HistoryPanel } from "./HistoryPanel";
|
||||
import {
|
||||
ToolsTabIcon,
|
||||
AttributesTabIcon,
|
||||
@@ -35,6 +36,7 @@ import {
|
||||
SiteTabIcon,
|
||||
RoomBalanceTabIcon,
|
||||
BcfTabIcon,
|
||||
HistoryTabIcon,
|
||||
} from "./PanelIcons";
|
||||
|
||||
/** IDs der eingebauten Dock-Panels (auch für defaultLayout/Filter nutzbar). */
|
||||
@@ -50,6 +52,7 @@ export const BUILTIN_PANEL_IDS = {
|
||||
viewSnapshots: "view-snapshots",
|
||||
layouts: "layouts",
|
||||
bcf: "bcf",
|
||||
history: "history",
|
||||
} as const;
|
||||
|
||||
// Werkzeug-Palette (Symbol + Name je Werkzeug, ArchiCAD/Vectorworks-Stil).
|
||||
@@ -158,3 +161,13 @@ registerPanel({
|
||||
hasDisplayMode: false,
|
||||
render: () => <BcfPanel />,
|
||||
});
|
||||
|
||||
// Verlauf ([84]) — Undo-Schritte als Liste, Klick springt zum Schritt. Nicht im Standard-Layout,
|
||||
// erreichbar über „Bearbeiten > Verlauf" bzw. „Fenster > Panels".
|
||||
registerPanel({
|
||||
id: BUILTIN_PANEL_IDS.history,
|
||||
title: "nav.history",
|
||||
icon: <HistoryTabIcon />,
|
||||
hasDisplayMode: false,
|
||||
render: () => <HistoryPanel />,
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
// Beschriftungen der Undo-Schritte ([84]). Der Kern speichert je Schritt einen kurzen Text: einen
|
||||
// i18n-Schlüssel (`history.…`, Sprache folgt der Oberfläche), `history.op.<art>:<liste>` (aus den Ops
|
||||
// abgeleitet) oder freien Text; leer = Standard.
|
||||
|
||||
import { t } from "../i18n";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
|
||||
/** Beschriftung aus den Ops (erste Op), wenn der Aufrufer keine setzt: `history.op.<art>:<liste>`. */
|
||||
export function opsLabel(ops: readonly CoreOp[]): string {
|
||||
const op = ops[0];
|
||||
if (!op) return "";
|
||||
return op.kind === "setField" ? `history.op.setField:${op.key}` : `history.op.${op.kind}:${op.collection}`;
|
||||
}
|
||||
|
||||
/** Anzeigetext eines Schritts in der aktuellen Sprache. */
|
||||
export function historyLabelText(label: string): string {
|
||||
if (!label) return t("history.step.generic");
|
||||
if (!label.startsWith("history.")) return label;
|
||||
const [key, arg] = label.split(":", 2);
|
||||
if (arg !== undefined) {
|
||||
const coll = t(`history.coll.${arg}`);
|
||||
return t(key!, { what: coll === `history.coll.${arg}` ? arg : coll });
|
||||
}
|
||||
const text = t(key!);
|
||||
return text === key ? t("history.step.generic") : text;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Verlaufsliste [84]: Beschriftungen der Schritte und Sprung zu einem Schritt über den Store.
|
||||
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { getState, setState } from "./appStore";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { withHistoryLabel } from "./historySlice";
|
||||
import { historyLabelText, opsLabel } from "./historyLabels";
|
||||
|
||||
beforeEach(() => {
|
||||
setState({ project: sampleProject, undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false });
|
||||
getState().clearHistory();
|
||||
});
|
||||
|
||||
const egVisible = () => getState().project.drawingLevels.find((l) => l.id === "eg")?.visible;
|
||||
|
||||
describe("Verlaufsliste", () => {
|
||||
it("Schritte tragen Beschriftungen (explizit, Gruppe)", () => {
|
||||
getState().toggleLevelVisible("eg");
|
||||
withHistoryLabel("Eigenschaft ändern: Dicke", () => getState().toggleLevelVisible("eg"));
|
||||
getState().groupChanges(
|
||||
() => {
|
||||
getState().toggleLevelVisible("eg");
|
||||
getState().toggleLevelVisible("eg");
|
||||
},
|
||||
undefined,
|
||||
"history.import",
|
||||
);
|
||||
const { undo, redo } = getState().historyEntries();
|
||||
expect(undo).toHaveLength(3);
|
||||
expect(undo[0]).toBe("history.op.replace:drawingLevels");
|
||||
expect(undo[1]).toBe("Eigenschaft ändern: Dicke");
|
||||
expect(undo[2]).toBe("history.import");
|
||||
expect(redo).toEqual([]);
|
||||
});
|
||||
|
||||
it("Anzeigetexte: Schlüssel, Ops-Ableitung, freier Text, Standard", () => {
|
||||
expect(opsLabel([])).toBe("");
|
||||
expect(opsLabel([{ kind: "add", collection: "walls", items: [] }])).toBe("history.op.add:walls");
|
||||
expect(historyLabelText("Eigenschaft ändern: Dicke")).toBe("Eigenschaft ändern: Dicke");
|
||||
expect(historyLabelText("")).toBe("Änderung");
|
||||
expect(historyLabelText("history.op.add:walls")).toBe("Wand hinzufügen");
|
||||
expect(historyLabelText("history.op.replace:unbekannt")).toBe("unbekannt ändern");
|
||||
expect(historyLabelText("history.gibtsnicht")).toBe("Änderung");
|
||||
expect(historyLabelText("history.cmd.wall")).toBe("Wand zeichnen");
|
||||
});
|
||||
|
||||
it("jumpHistory springt über mehrere Schritte und zurück", () => {
|
||||
const start = egVisible();
|
||||
for (let i = 0; i < 3; i++) getState().toggleLevelVisible("eg");
|
||||
const after3 = egVisible();
|
||||
expect(after3).toBe(!start);
|
||||
getState().jumpHistory(1);
|
||||
expect(getState().undoDepth).toBe(1);
|
||||
expect(getState().redoDepth).toBe(2);
|
||||
expect(egVisible()).toBe(!start);
|
||||
expect(getState().historyEntries().redo).toHaveLength(2);
|
||||
getState().jumpHistory(0);
|
||||
expect(egVisible()).toBe(start);
|
||||
expect(getState().canUndo).toBe(false);
|
||||
getState().jumpHistory(3);
|
||||
expect(egVisible()).toBe(after3);
|
||||
expect(getState().canRedo).toBe(false);
|
||||
getState().jumpHistory(99);
|
||||
expect(getState().undoDepth).toBe(3);
|
||||
});
|
||||
});
|
||||
@@ -38,7 +38,36 @@ export interface HistorySlice {
|
||||
* Alle Projekt-Änderungen in `fn` werden EIN Undo-Schritt. Mit `coalesceKey` schliessen
|
||||
* aufeinanderfolgende Gruppen mit gleichem Schlüssel (im Zeitfenster) an denselben Schritt an.
|
||||
*/
|
||||
groupChanges: (fn: () => void, coalesceKey?: string) => void;
|
||||
groupChanges: (fn: () => void, coalesceKey?: string, label?: string) => void;
|
||||
/** Beschriftungen der Schritte (Undo: ältester zuerst; Redo: nächster zuerst), für die Verlaufsliste [84]. */
|
||||
historyEntries: () => { undo: string[]; redo: string[] };
|
||||
/** Springt auf Undo-Tiefe `target` (0 = Anfang), mehrere Schritte in einem Kern-Aufruf. */
|
||||
jumpHistory: (target: number) => void;
|
||||
}
|
||||
|
||||
let activeLabel = "";
|
||||
|
||||
/** Alle Änderungen in `fn` ohne eigene Beschriftung bekommen `label` (i18n-Schlüssel oder Text) als Schritt-Name. */
|
||||
export function withHistoryLabel<T>(label: string, fn: () => T): T {
|
||||
const prev = activeLabel;
|
||||
activeLabel = label;
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
activeLabel = prev;
|
||||
}
|
||||
}
|
||||
|
||||
/** Führt einen Commit mit Beschriftung aus: die des umgebenden {@link withHistoryLabel}, sonst `fallback`. */
|
||||
export function labelCommit<T>(d: ProjectDocument, fallback: string, run: () => T): T {
|
||||
const label = activeLabel || fallback;
|
||||
if (!label) return run();
|
||||
d.setHistoryLabel(label);
|
||||
try {
|
||||
return run();
|
||||
} finally {
|
||||
d.setHistoryLabel("");
|
||||
}
|
||||
}
|
||||
|
||||
let doc: ProjectDocument | null = null;
|
||||
@@ -85,15 +114,23 @@ export function createHistorySlice(api: StoreApi<HistorySlice & { project: Proje
|
||||
d.clearHistory();
|
||||
set(historyPatch(d));
|
||||
},
|
||||
groupChanges: (fn, coalesceKey) => {
|
||||
groupChanges: (fn, coalesceKey, label) => {
|
||||
const d = storeDocument(get().project);
|
||||
if (coalesceKey) d.beginKeyedGroup(coalesceKey, Date.now());
|
||||
else d.beginGroup();
|
||||
try {
|
||||
fn();
|
||||
if (label) withHistoryLabel(label, fn);
|
||||
else fn();
|
||||
} finally {
|
||||
d.endGroup();
|
||||
}
|
||||
},
|
||||
historyEntries: () => storeDocument(get().project).historyLabels(),
|
||||
jumpHistory: (target) => {
|
||||
const { project } = get();
|
||||
const d = storeDocument(project);
|
||||
const next = d.jumpTo(project, target);
|
||||
if (next) set({ project: next, ...historyPatch(d) });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -66,8 +66,9 @@ import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
|
||||
import { DEFAULT_PRESETS, type TextStylePreset } from "../text/richText";
|
||||
import { t } from "../i18n";
|
||||
import type { StoreApi } from "./store";
|
||||
import { createHistorySlice, historyPatch, storeDocument } from "./historySlice";
|
||||
import { createHistorySlice, historyPatch, labelCommit, storeDocument } from "./historySlice";
|
||||
import type { HistorySlice } from "./historySlice";
|
||||
import { opsLabel } from "./historyLabels";
|
||||
import type { NotifyKind } from "./notifySlice";
|
||||
|
||||
/** Felder, die diese Slice in den RootState beisteuert. */
|
||||
@@ -97,6 +98,7 @@ export interface ProjectSlice {
|
||||
*/
|
||||
commitImport: <R extends object>(
|
||||
run: (doc: ProjectDocument, base: Project, now: number) => ({ project: Project; ops: CoreOp[] } & R) | { problems: string[] },
|
||||
label?: string,
|
||||
) => ({ ops: CoreOp[] } & R) | null;
|
||||
/**
|
||||
* Ein anderes Projekt übernehmen (Neu, Musterhaus; [K4] S4): lädt es als Ganzes ins Kern-Dokument
|
||||
@@ -485,7 +487,7 @@ export function createProjectSlice(
|
||||
): Partial<ProjectSlice & HistorySlice> => {
|
||||
if (ops.length === 0) return {};
|
||||
const doc = storeDocument(s.project);
|
||||
const res = doc.commit(s.project, ops, coalesceKey, Date.now());
|
||||
const res = labelCommit(doc, opsLabel(ops), () => doc.commit(s.project, ops, coalesceKey, Date.now()));
|
||||
if ("problems" in res) {
|
||||
const problems = res.problems;
|
||||
console.warn("Projektänderung verworfen:", problems);
|
||||
@@ -509,7 +511,10 @@ export function createProjectSlice(
|
||||
const applyCmd = (req: object, coalesceKey?: string) =>
|
||||
set((s) => {
|
||||
const doc = storeDocument(s.project);
|
||||
const res = doc.commitCmd(s.project, req, coalesceKey, Date.now());
|
||||
const cmd = (req as { cmd?: unknown }).cmd;
|
||||
const res = labelCommit(doc, typeof cmd === "string" ? `history.cmd.${cmd}` : "", () =>
|
||||
doc.commitCmd(s.project, req, coalesceKey, Date.now()),
|
||||
);
|
||||
if ("problems" in res) {
|
||||
const problems = res.problems;
|
||||
console.warn("Projektänderung verworfen:", problems);
|
||||
@@ -534,7 +539,7 @@ export function createProjectSlice(
|
||||
let notice: string | undefined;
|
||||
set((s) => {
|
||||
const doc = storeDocument(s.project);
|
||||
const res = doc.commitGrip(s.project, req, coalesceKey, Date.now());
|
||||
const res = labelCommit(doc, "history.grip", () => doc.commitGrip(s.project, req, coalesceKey, Date.now()));
|
||||
if ("problems" in res) {
|
||||
const problems = res.problems;
|
||||
console.warn("Projektänderung verworfen:", problems);
|
||||
@@ -563,11 +568,11 @@ export function createProjectSlice(
|
||||
applyChange,
|
||||
recentOps: () => opLog.slice(),
|
||||
|
||||
commitImport: (run) => {
|
||||
commitImport: (run, label) => {
|
||||
let out: ReturnType<typeof run> | null = null;
|
||||
set((s) => {
|
||||
const doc = storeDocument(s.project);
|
||||
const res = run(doc, s.project, Date.now());
|
||||
const res = labelCommit(doc, label ?? "history.import", () => run(doc, s.project, Date.now()));
|
||||
out = res;
|
||||
if ("problems" in res) {
|
||||
const problems = res.problems;
|
||||
|
||||
@@ -599,6 +599,7 @@ export function useProjectFileActions(
|
||||
},
|
||||
now,
|
||||
),
|
||||
"history.import.drawing",
|
||||
);
|
||||
} catch (err) {
|
||||
// Kaputter Puffer o. Ä. (Meldung des Kerns).
|
||||
|
||||
@@ -8687,3 +8687,33 @@ body {
|
||||
.rpi-state {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* Verlauf-Panel [84]: Zeilen wie .nav-row (eigene Klasse, damit der Element-Baum sie nicht mitzählt). */
|
||||
.history-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: 26px;
|
||||
padding: 2px 10px 2px 10px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
color: var(--label);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.history-row:hover {
|
||||
background: var(--panel-2);
|
||||
}
|
||||
.history-row.active {
|
||||
background: var(--active-dim);
|
||||
border-radius: 999px;
|
||||
border-bottom-color: transparent;
|
||||
color: var(--active-light);
|
||||
}
|
||||
.history-row.active .nav-label {
|
||||
font-weight: 600;
|
||||
color: var(--active-light);
|
||||
}
|
||||
.history-row.future {
|
||||
opacity: 0.45;
|
||||
}
|
||||
@@ -51,6 +51,8 @@ export interface AppMenuBarProps {
|
||||
onOpenSettings: () => void;
|
||||
/** BCF-Themen-Panel öffnen (`revealPanel`); ohne diese Funktion entfällt der Menüpunkt. */
|
||||
onOpenBcf?: () => void;
|
||||
/** Verlauf-Panel öffnen ([84]). */
|
||||
onOpenHistory?: () => void;
|
||||
}
|
||||
|
||||
/** Menüleiste (Bearbeiten/Ansicht/Fenster) — sitzt in der TopBar neben der Wortmarke. */
|
||||
@@ -83,6 +85,7 @@ export function AppMenuBar({
|
||||
onToggleResources,
|
||||
onOpenSettings,
|
||||
onOpenBcf,
|
||||
onOpenHistory,
|
||||
}: AppMenuBarProps) {
|
||||
const fileItems: DropdownItem[] = [
|
||||
{ label: t("file.new"), onSelect: onNewProject },
|
||||
@@ -105,6 +108,7 @@ export function AppMenuBar({
|
||||
const editItems: DropdownItem[] = [
|
||||
{ label: t("menu.edit.undo"), onSelect: onUndo, disabled: !canUndo },
|
||||
{ label: t("menu.edit.redo"), onSelect: onRedo, disabled: !canRedo },
|
||||
...(onOpenHistory ? [{ label: t("nav.history"), onSelect: onOpenHistory }] : []),
|
||||
{ divider: true },
|
||||
{
|
||||
label: t("menu.edit.delete"),
|
||||
|
||||
Reference in new issue
Block a user