Nutzer-Report: Textfelder waren nicht mehrzeilig. Ursache: die Text-/ Textspalte-Werkzeuge holten ihre Eingabe über die Befehlszeile (CommandLine.tsx) — ein einzeiliges <input>, Enter committet sofort, kein Zeilenumbruch möglich. Das betraf auch "Textspalte", obwohl die explizit für mehrzeiligen Wortumbruch gedacht ist. Lösung (Nutzer-Vorgabe: kein Dialog, direktes Editieren auf der Fläche wie im Layout-System): text.ts/textbox.ts committen nach dem Platzieren (Anker bzw. Anker+Breite) sofort ein LEERES Text-Element und melden `focusDrawingId` — dafür CommandResult/EngineHost um einen Passthrough erweitert (engine.ts applyResult ruft host.focusDrawing(id)). App.tsx setzt darauf Auswahl + editTextId (dieselbe State-Variable wie beim bisherigen Doppelklick-Editieren). PlanView rendert bei gesetztem editTextId jetzt einen RichTextEditor-Overlay direkt über dem Element (position:fixed via vbToClient/toScreen, eigene Mini-Toolbar erscheint darüber) statt des bisherigen TextEditorDialog-Modals — Prinzip 1:1 vom Layout-Blatt-Inline- Editor (LayoutSheet.tsx) übernommen. Die neuen Props (editTextId/ onCommitTextEdit/onCloseTextEdit) laufen durch Content/LevelPlanView/ SectionPlanView (viewportContent.tsx) bis zu PlanView durch. Verhalten der beiden Werkzeuge (Nutzer-Vorgabe): "text" bleibt ohne Wortumbruch (kein `width`) — Enter erzeugt weitere Zeilen, aber keine automatische Breite. "textbox" setzt `width` und verhält sich damit wie ein InDesign-Textrahmen (echter Wortumbruch live beim Tippen, kein reines Render-Detail mehr). commitTextEdit (useMouseSelectionHandlers.ts) schreibt jetzt bei JEDEM Tastendruck (kein Guard mehr gegen leeren Text — nötig, damit Löschen bis auf null Zeichen sich sofort spiegelt); neues closeTextEdit räumt ein beim Schliessen noch leeres Element auf (verhindert Leichen bei abgebrochener Neuerstellung). 4 neue Tests (text/textbox: sofortiger Commit + focusDrawingId). tsc -b / vitest run (918/918) / npm run build grün. Rendering/Positionierung des Overlays selbst nicht automatisiert testbar — Nutzer prüft visuell in der Tauri-App.
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
// Text — modellverankerter Einzeltext als 2D-Element. Schritte:
|
|
// 1) „Ankerpunkt:" → Punkt (Position im Modell)
|
|
// Committet SOFORT ein leeres Text-Element und meldet `focusDrawingId` —
|
|
// die UI (PlanView) öffnet daraufhin direkt den Inline-Rich-Text-Editor AUF
|
|
// der Zeichenfläche (kein Dialog, keine Befehlszeilen-Eingabe). Ohne
|
|
// Spaltenbreite bricht der Text NICHT automatisch um: einzeilig, bis der
|
|
// Nutzer selbst Enter drückt (siehe `textbox` fürs InDesign-artige
|
|
// Wortumbruch-Textfeld). Bleibt der Editor leer, verwirft `commitTextEdit`
|
|
// (App.tsx) das Element wieder.
|
|
|
|
import type { Drawing2D } from "../../model/types";
|
|
import { uniqueId } from "../../tools/types";
|
|
import type { Command, CommandContext, CommandResult, CommandState, Project, Vec2 } from "../types";
|
|
|
|
/** Default-Schrifthöhe eines frei platzierten Texts in Modell-Metern. */
|
|
const DEFAULT_TEXT_HEIGHT_M = 0.25;
|
|
|
|
interface TextIdle extends CommandState {
|
|
phase: "point";
|
|
}
|
|
type TextState = TextIdle;
|
|
|
|
function appendEmptyText(p: Project, id: string, at: Vec2, ctx: CommandContext): Project {
|
|
const d: Drawing2D = {
|
|
id,
|
|
type: "drawing2d",
|
|
levelId: ctx.level.id,
|
|
categoryCode: ctx.defaultCategoryCode,
|
|
geom: { shape: "text", at, text: "", height: DEFAULT_TEXT_HEIGHT_M, angle: 0 },
|
|
};
|
|
return { ...p, drawings2d: [...p.drawings2d, d] };
|
|
}
|
|
|
|
const idle = (): [CommandState, CommandResult] => [
|
|
{ phase: "point", lastPoint: null } as TextIdle,
|
|
{ draft: null, done: true },
|
|
];
|
|
|
|
export const textCommand: Command = {
|
|
name: "text",
|
|
labelKey: "cmd.text.label",
|
|
prompt: () => "cmd.text.point",
|
|
accepts: () => ["point"],
|
|
options: () => [],
|
|
init: (): TextIdle => ({ phase: "point", lastPoint: null }),
|
|
|
|
onInput: (state, input, ctx): [CommandState, CommandResult] => {
|
|
const s = state as TextState;
|
|
if (input.kind !== "point") return [s, { draft: null }];
|
|
const id = uniqueId("dr2d");
|
|
const at = input.point;
|
|
return [
|
|
{ phase: "point", lastPoint: null } as TextIdle,
|
|
{
|
|
draft: null,
|
|
done: true,
|
|
commit: (p) => appendEmptyText(p, id, at, ctx),
|
|
focusDrawingId: id,
|
|
},
|
|
];
|
|
},
|
|
|
|
onMove: (state): [CommandState, CommandResult] => [state, { draft: null }],
|
|
onConfirm: (): [CommandState, CommandResult] => idle(),
|
|
onCancel: (): [CommandState, CommandResult] => idle(),
|
|
};
|