task(C3fin-int): interactive handle drag for select tool (scale by corner)

This commit is contained in:
Agent Zero
2026-08-27 20:00:33 +02:00
parent 8223d159f8
commit 5605993462
2 changed files with 225 additions and 1 deletions
+62
View File
@@ -860,3 +860,65 @@ describe('D-Ext: array-polar tool', () => {
expect(doc.getAllElements().length).toBe(1);
});
});
describe('C3fin interaktiv: handle-drag on select tool', () => {
function makeRect(id: string, x: number, y: number, w: number, h: number): CADElement {
return {
id, type: 'rect', layerId: 'l',
x: x + w / 2, y: y + h / 2,
width: w, height: h,
properties: { fill: '#abc' },
} as unknown as CADElement;
}
it('down auf Handle startet Drag, move skaliert, up committet', () => {
const { ydoc } = createInMemoryDoc();
const doc = new CADDocument(ydoc);
// Rect: (0,0) bis (50,50)
doc.addElement(makeRect('r1', 0, 0, 50, 50));
let selIds: string[] = ['r1'];
const bridge = {
getIds: () => selIds,
setIds: (ids: string[]) => { selIds = ids; },
hitTest: () => null,
};
const ctx = makeCtx({ doc, selection: bridge });
const select = coreModifyPlugin.tools!.find((t) => t.manifest.id === 'select')!;
// down auf Handle der oberen linken Ecke (0,0):
select.handlers.down!(pe(0, 0), ctx);
// move zu neuem Punkt (-20, -20):
select.handlers.move!(pe(-20, -20), ctx);
// up → Commit (Skalierung auf neue BBox von (-20,-20) bis (50,50)):
select.handlers.up!(pe(-20, -20), ctx);
const updated = doc.getElement('r1')!;
// Neue BBox: 70×70 statt 50×50:
expect(updated.width).toBe(70);
expect(updated.height).toBe(70);
expect(doc.undo()).toBe(true); // Skalierung ist undo-bar
expect(doc.getElement('r1')!.width).toBe(50);
});
it('down auf NICHT-Handle startet normale Selektion (kein Drag)', () => {
const { ydoc } = createInMemoryDoc();
const doc = new CADDocument(ydoc);
doc.addElement(makeRect('r2', 0, 0, 50, 50));
doc.addElement(makeRect('r3', 200, 200, 30, 30));
let selIds: string[] = ['r2'];
const bridge = {
getIds: () => selIds,
setIds: (ids: string[]) => { selIds = ids; },
// Klick bei (210,210) trifft r3:
hitTest: () => doc.getElement('r3')!,
};
const ctx = makeCtx({ doc, selection: bridge });
const select = coreModifyPlugin.tools!.find((t) => t.manifest.id === 'select')!;
// Klick weit weg von Handles von r2 (r2-Ecken sind 0/50):
select.handlers.down!(pe(210, 210), ctx);
// Normal-Selektion: r3 ist jetzt alleine selektiert (kein Drag gestartet):
expect(selIds).toEqual(['r3']);
});
});