Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(appshot): grab, move and reshape any annotation with any tool

rubenluetke10-beepe4314014c8a4
diff --git a/docs/appshots.md b/docs/appshots.md
index 8fe44846da..77be87edd7 100644
--- a/docs/appshots.md
+++ b/docs/appshots.md
@@ -119,7 +119,15 @@ app. Nothing navigates away.
| Key | Tool | What it does |
|---|---|---|
-| V | Select and move | Click an annotation to select it; drag moves it, arrow keys nudge it (Shift = 10 px), Delete removes it. Double-click a text to change it. |
+| V | Select and move | Click an annotation to select it; drag moves it, arrow keys nudge it (Shift = 10 px), Delete removes it. Double-click a text to change it. The only tool that also picks spotlights and redactions. |
+
+With **any** tool, an annotation can be taken by the hand: the pointer turns
+into a move cursor over it, a drag moves it, and a click selects it. A fresh
+annotation is selected right away. A selected one shows round grips — at both
+ends of an arrow or line (drag the tip somewhere else), at the corners of a
+box, a stroke or a redaction (resize from the opposite corner), at a text's
+corner (its size) and on a counter's rim (the badge's size). Every move and
+reshape is one undo step.
| A / L | Arrow / Line | Shift snaps to 45°. |
| R / F / E | Rectangle / Filled rectangle / Ellipse | Shift makes a square or circle. |
| D | Draw | Freehand, smoothed. |
diff --git a/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.test.tsx b/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.test.tsx
index 7507542caf..abee330586 100644
--- a/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/appshot/AppshotEditorHost.test.tsx
@@ -107,6 +107,10 @@ describe("AppshotEditorHost", () => {
const undoButton = screen.getByTestId("appshot-editor-undo") as HTMLButtonElement;
await waitFor(() => expect(undoButton.disabled).toBe(false));
+ // A fresh annotation is selected: the first Escape lets go of it, the
+ // next one asks before throwing the edits away.
+ fireEvent.keyDown(window, { key: "Escape" });
+ expect(screen.queryByTestId("appshot-editor-discard")).toBeNull();
fireEvent.keyDown(window, { key: "Escape" });
expect(await screen.findByTestId("appshot-editor-discard")).toBeDefined();
// Escape again keeps editing.
@@ -174,6 +178,38 @@ describe("AppshotEditorHost", () => {
expect((screen.getByTestId("appshot-editor-size") as HTMLInputElement).value).toBe("4");
});
+ it("takes any annotation by the hand: drag moves it, a grip reshapes it", async () => {
+ render(<AppshotEditorHost />);
+ act(() => useAppshotEditor.getState().open("shot-1"));
+ const canvas = await screen.findByTestId("appshot-editor-canvas");
+ const undo = () => screen.getByTestId("appshot-editor-undo") as HTMLButtonElement;
+ const steps = () => {
+ let n = 0;
+ while (!undo().disabled && n < 10) {
+ fireEvent.keyDown(window, { key: "z", ctrlKey: true });
+ n += 1;
+ }
+ return n;
+ };
+
+ // Draw an arrow with the arrow tool (the default)...
+ fireEvent.pointerDown(canvas, { button: 0, clientX: 20, clientY: 20, pointerId: 1 });
+ fireEvent.pointerMove(canvas, { clientX: 200, clientY: 120, pointerId: 1 });
+ fireEvent.pointerUp(canvas, { clientX: 200, clientY: 120, pointerId: 1 });
+ // ...then, with the same tool, drag its tip grip somewhere else...
+ fireEvent.pointerDown(canvas, { button: 0, clientX: 200, clientY: 120, pointerId: 2 });
+ fireEvent.pointerMove(canvas, { clientX: 300, clientY: 60, pointerId: 2 });
+ fireEvent.pointerUp(canvas, { clientX: 300, clientY: 60, pointerId: 2 });
+ // ...and the arrow itself, from its middle.
+ fireEvent.pointerDown(canvas, { button: 0, clientX: 160, clientY: 40, pointerId: 3 });
+ fireEvent.pointerMove(canvas, { clientX: 180, clientY: 90, pointerId: 3 });
+ fireEvent.pointerUp(canvas, { clientX: 180, clientY: 90, pointerId: 3 });
+
+ // Drawing, reshaping and moving are three steps — never a second arrow.
+ await waitFor(() => expect(undo().disabled).toBe(false));
+ expect(steps()).toBe(3);
+ });
+
it("says when the appshot is gone instead of showing an empty editor", async () => {
vi.stubGlobal("Image", BrokenImage);
render(<AppshotEditorHost />);
diff --git a/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts
index 7a79d2e028..764256f2f2 100644
--- a/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts
+++ b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.test.ts
@@ -2,6 +2,10 @@ import { describe, expect, it } from "vitest";
import {
ARROW_STYLES,
+ handleAt,
+ handleCursor,
+ handles,
+ reshape,
BACKGROUND_PRESETS,
DEFAULT_BACKGROUND,
TOOL_KEYS,
@@ -246,3 +250,48 @@ describe("tapered arrow", () => {
expect(ARROW_STYLES).toEqual(["tapered", "classic", "double"]);
});
});
+
+describe("grips", () => {
+ const arrow = withId({ kind: "arrow", from: { x: 10, y: 10 }, to: { x: 110, y: 60 }, color: "#f00", width: 4 });
+ const box = withId({ kind: "rect", rect: { x: 100, y: 100, w: 80, h: 40 }, color: "#f00", width: 4 });
+
+ it("puts a grip at each end of an arrow and each corner of a box", () => {
+ expect(handles(arrow).map((h) => h.id)).toEqual(["from", "to"]);
+ expect(handles(box).map((h) => h.id)).toEqual(["nw", "ne", "sw", "se"]);
+ expect(handles(withId({ kind: "crop", rect: { x: 0, y: 0, w: 5, h: 5 } }))).toEqual([]);
+ });
+
+ it("finds the grip under the pointer", () => {
+ expect(handleAt(arrow, { x: 112, y: 58 }, 6)).toBe("to");
+ expect(handleAt(arrow, { x: 60, y: 35 }, 6)).toBeNull();
+ expect(handleAt(box, { x: 181, y: 141 }, 6)).toBe("se");
+ });
+
+ it("moves an arrow's tip and leaves its tail", () => {
+ const moved = reshape(arrow, "to", { x: 200, y: 20 });
+ expect(moved.to).toEqual({ x: 200, y: 20 });
+ expect(moved.from).toEqual(arrow.from);
+ expect(moved.id).toBe(arrow.id);
+ });
+
+ it("resizes a box from the corner held, keeping the opposite one", () => {
+ expect(reshape(box, "se", { x: 220, y: 200 }).rect).toEqual({ x: 100, y: 100, w: 120, h: 100 });
+ // Dragged past the opposite corner, the box flips instead of going negative.
+ expect(reshape(box, "nw", { x: 200, y: 160 }).rect).toEqual({ x: 180, y: 140, w: 20, h: 20 });
+ });
+
+ it("scales a stroke, a text and a counter", () => {
+ const pen = withId({ kind: "pen", points: [{ x: 0, y: 0 }, { x: 10, y: 10 }], color: "#f00", width: 3 });
+ expect(reshape(pen, "se", { x: 20, y: 20 }).points[1]).toEqual({ x: 20, y: 20 });
+ const text = withId({ kind: "text", at: { x: 0, y: 0 }, text: "Hi", color: "#fff", size: 20, style: "plain" as const });
+ expect(reshape(text, "se", { x: 0, y: 50 }, () => 20).size).toBe(40);
+ const badge = withId({ kind: "counter", at: { x: 0, y: 0 }, n: 1, color: "#f00", size: 12 });
+ expect(reshape(badge, "size", { x: 30, y: 0 }).size).toBe(30);
+ });
+
+ it("shows a cursor that fits the grip", () => {
+ expect(handleCursor("se")).toBe("nwse-resize");
+ expect(handleCursor("ne")).toBe("nesw-resize");
+ expect(handleCursor("to")).toBe("grab");
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts
index 6d881426b0..70921dc75b 100644
--- a/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts
+++ b/jarvis/ui/web/frontend/src/lib/appshotEditorModel.ts
@@ -281,8 +281,14 @@ function hits(op: Op, p: Point, slop: number, measure?: MeasureText): boolean {
* anywhere on them. Spotlights and redactions come last — they cover
* whatever sits in them — and crops are never picked.
*/
-export function hitTest(ops: readonly Op[], p: Point, slop: number, measure?: MeasureText): Op | null {
- for (const areas of [false, true]) {
+export function hitTest(
+ ops: readonly Op[],
+ p: Point,
+ slop: number,
+ measure?: MeasureText,
+ { areas: withAreas = true }: { areas?: boolean } = {},
+): Op | null {
+ for (const areas of withAreas ? [false, true] : [false]) {
for (let i = ops.length - 1; i >= 0; i -= 1) {
const op = ops[i];
if (AREA_KINDS.has(op.kind) !== areas) continue;
@@ -313,6 +319,122 @@ export function translate<T extends Draft>(op: T, dx: number, dy: number): T {
}
}
+// -- handles: reshaping an annotation in place --------------------------------
+
+/**
+ * A grip on a selected annotation. Lines and arrows have one at each end
+ * (``from``, ``to``); boxes and strokes one at each corner; text a corner
+ * that scales its size; a counter one on its rim (``size``).
+ */
+export type HandleId = "from" | "to" | "nw" | "ne" | "sw" | "se" | "size";
+
+export interface Handle {
+ id: HandleId;
+ at: Point;
+}
+
+const OPPOSITE: Record<"nw" | "ne" | "sw" | "se", "nw" | "ne" | "sw" | "se"> = {
+ nw: "se",
+ ne: "sw",
+ sw: "ne",
+ se: "nw",
+};
+
+function corner(box: Rect, id: "nw" | "ne" | "sw" | "se"): Point {
+ return {
+ x: id === "nw" || id === "sw" ? box.x : box.x + box.w,
+ y: id === "nw" || id === "ne" ? box.y : box.y + box.h,
+ };
+}
+
+/** The grips a selected annotation shows. */
+export function handles(op: Draft, measure?: MeasureText): Handle[] {
+ switch (op.kind) {
+ case "arrow":
+ case "line":
+ return [
+ { id: "from", at: op.from },
+ { id: "to", at: op.to },
+ ];
+ case "crop":
+ return [];
+ case "counter":
+ return [{ id: "size", at: { x: op.at.x + op.size, y: op.at.y } }];
+ case "text":
+ return [{ id: "se", at: corner(bounds(op, measure), "se") }];
+ default: {
+ const box = bounds(op, measure);
+ return (["nw", "ne", "sw", "se"] as const).map((id) => ({ id, at: corner(box, id) }));
+ }
+ }
+}
+
+/** The grip under `p` (within `radius`), nearest first; null when none. */
+export function handleAt(op: Draft, p: Point, radius: number, measure?: MeasureText): HandleId | null {
+ let best: HandleId | null = null;
+ let bestDistance = radius;
+ for (const handle of handles(op, measure)) {
+ const distance = Math.hypot(handle.at.x - p.x, handle.at.y - p.y);
+ if (distance <= bestDistance) {
+ best = handle.id;
+ bestDistance = distance;
+ }
+ }
+ return best;
+}
+
+/**
+ * ``original`` with grip ``handle`` dragged to ``p``. Always computed from
+ * the shape as it was when the drag began, so a long drag never drifts.
+ * An arrow's end follows the pointer; a box keeps the opposite corner
+ * fixed; a stroke scales from it; text grows with its corner; a counter's
+ * badge grows with its rim.
+ */
+export function reshape<T extends Draft>(original: T, handle: HandleId, p: Point, measure?: MeasureText): T {
+ const op = original as Draft;
+ switch (op.kind) {
+ case "arrow":
+ case "line":
+ if (handle === "from") return { ...op, from: p } as T;
+ if (handle === "to") return { ...op, to: p } as T;
+ return original;
+ case "crop":
+ return original;
+ case "counter":
+ return { ...op, size: Math.max(8, Math.hypot(p.x - op.at.x, p.y - op.at.y)) } as T;
+ case "text": {
+ const box = bounds(op, measure);
+ const factor = Math.max(0.25, (p.y - box.y) / Math.max(1, box.h));
+ return { ...op, size: Math.max(8, Math.round(op.size * factor)) } as T;
+ }
+ case "pen":
+ case "highlight": {
+ if (handle === "from" || handle === "to" || handle === "size") return original;
+ const box = bounds(op);
+ const anchor = corner(box, OPPOSITE[handle]);
+ const grip = corner(box, handle);
+ const sx = Math.abs(grip.x - anchor.x) < 1e-6 ? 1 : (p.x - anchor.x) / (grip.x - anchor.x);
+ const sy = Math.abs(grip.y - anchor.y) < 1e-6 ? 1 : (p.y - anchor.y) / (grip.y - anchor.y);
+ return {
+ ...op,
+ points: op.points.map((q) => ({ x: anchor.x + (q.x - anchor.x) * sx, y: anchor.y + (q.y - anchor.y) * sy })),
+ } as T;
+ }
+ default: {
+ if (handle === "from" || handle === "to" || handle === "size") return original;
+ return { ...op, rect: rectFrom(corner(op.rect, OPPOSITE[handle]), p) } as T;
+ }
+ }
+}
+
+/** The pointer cursor that fits a grip. */
+export function handleCursor(handle: HandleId): string {
+ if (handle === "nw" || handle === "se") return "nwse-resize";
+ if (handle === "ne" || handle === "sw") return "nesw-resize";
+ if (handle === "size") return "ew-resize";
+ return "grab";
+}
+
/** Is this freshly drawn shape big enough to keep (not a stray click)? */
export function isMeaningful(op: Draft): boolean {
switch (op.kind) {
diff --git a/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx b/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx
index 79cecee35a..f8f9ac5c38 100644
--- a/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx
+++ b/jarvis/ui/web/frontend/src/views/AppshotEditor.tsx
@@ -58,6 +58,11 @@ import {
strokeWidths,
textSize,
toolForKey,
+ handleAt,
+ handleCursor,
+ handles,
+ reshape,
+ type HandleId,
translate,
undo as undoHistory,
viewport,
@@ -137,6 +142,8 @@ const TOOL_ICONS: Record<Tool, typeof Square | null> = {
const COLOR_KEY = "jarvis.appshotEditor.color";
+/** Radius of a selection grip, in screen pixels. */
+const GRIP_RADIUS = 5;
const ARROW_KEY = "jarvis.appshotEditor.arrowStyle";
const BACKGROUND_KEY = "jarvis.appshotEditor.background";
@@ -172,7 +179,9 @@ function stamp(): string {
type Gesture =
| { kind: "draw"; shape: Draft; start: Point }
- | { kind: "move"; id: number; start: Point; dx: number; dy: number };
+ | { kind: "move"; id: number; start: Point; dx: number; dy: number }
+ /** A grip of the selected annotation being dragged; `original` as it was. */
+ | { kind: "resize"; id: number; handle: HandleId; original: Op; at: Point };
type LoadState = "loading" | "ready" | "failed";
@@ -331,17 +340,28 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
const ch = Math.max(1, Math.round(shown.h * scale));
const ratio = CROP_RATIOS.find((entry) => entry.id === cropRatio)?.ratio ?? null;
- // What is on screen: the document, a move in progress, and the shape being drawn.
+ // An annotation as it looks right now: moved or reshaped by the drag in progress.
+ const live = useCallback(
+ (op: Op): Op => {
+ if (gesture?.kind === "move" && gesture.id === op.id) return translate(op, gesture.dx, gesture.dy);
+ if (gesture?.kind === "resize" && gesture.id === op.id) {
+ return reshape(gesture.original, gesture.handle, gesture.at, measure);
+ }
+ return op;
+ },
+ [gesture, measure],
+ );
+
+ // What is on screen: the document, a move or reshape in progress, and the shape being drawn.
const drawn = useMemo<Draft[]>(() => {
- const live: Draft[] =
- gesture?.kind === "move"
- ? ops.map((op) => (op.id === gesture.id ? translate(op, gesture.dx, gesture.dy) : op))
- : [...ops];
- if (gesture?.kind === "draw" && gesture.shape.kind !== "crop") live.push(gesture.shape);
- return live;
- }, [gesture, ops]);
+ const shapes: Draft[] = ops.map(live);
+ if (gesture?.kind === "draw" && gesture.shape.kind !== "crop") shapes.push(gesture.shape);
+ return shapes;
+ }, [gesture, live, ops]);
const selected = selectedId === null ? null : ops.find((op) => op.id === selectedId) ?? null;
+ const selectedLive = selected ? live(selected) : null;
+ const [hoverCursor, setHoverCursor] = useState<string | null>(null);
// -- paint ---------------------------------------------------------------
useEffect(() => {
@@ -368,24 +388,37 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
ctx.strokeRect(crop.x, crop.y, crop.w, crop.h);
ctx.restore();
}
- const outlined =
- selected && gesture?.kind === "move" && gesture.id === selected.id
- ? translate(selected, gesture.dx, gesture.dy)
- : selected;
- if (outlined) {
- const box = bounds(outlined, measure);
- const pad = 6 / scale;
+ if (selectedLive) {
+ // The selection: a dashed frame (not for a line or an arrow, whose two
+ // grips say it all) and a round grip wherever it can be reshaped.
ctx.save();
- ctx.lineWidth = 1.5 / scale;
- ctx.setLineDash([5 / scale, 4 / scale]);
- ctx.strokeStyle = "rgba(0,0,0,0.6)";
- ctx.strokeRect(box.x - pad, box.y - pad, box.w + pad * 2, box.h + pad * 2);
- ctx.lineDashOffset = 4.5 / scale;
- ctx.strokeStyle = "#ffffff";
- ctx.strokeRect(box.x - pad, box.y - pad, box.w + pad * 2, box.h + pad * 2);
+ if (selectedLive.kind !== "arrow" && selectedLive.kind !== "line") {
+ const box = bounds(selectedLive, measure);
+ const pad = 6 / scale;
+ ctx.lineWidth = 1.5 / scale;
+ ctx.setLineDash([5 / scale, 4 / scale]);
+ ctx.strokeStyle = "rgba(0,0,0,0.6)";
+ ctx.strokeRect(box.x - pad, box.y - pad, box.w + pad * 2, box.h + pad * 2);
+ ctx.lineDashOffset = 4.5 / scale;
+ ctx.strokeStyle = "#ffffff";
+ ctx.strokeRect(box.x - pad, box.y - pad, box.w + pad * 2, box.h + pad * 2);
+ ctx.setLineDash([]);
+ }
+ for (const grip of handles(selectedLive, measure)) {
+ ctx.beginPath();
+ ctx.arc(grip.at.x, grip.at.y, GRIP_RADIUS / scale, 0, Math.PI * 2);
+ ctx.fillStyle = "#ffffff";
+ ctx.shadowColor = "rgba(0,0,0,0.45)";
+ ctx.shadowBlur = 4 / scale;
+ ctx.fill();
+ ctx.shadowColor = "transparent";
+ ctx.lineWidth = 1.5 / scale;
+ ctx.strokeStyle = "#0a84ff";
+ ctx.stroke();
+ }
ctx.restore();
}
- }, [image, drawn, gesture, tool, cw, ch, scale, shown.x, shown.y, shown.w, shown.h, iw, ih, view, selected, measure]);
+ }, [image, drawn, gesture, tool, cw, ch, scale, shown.x, shown.y, shown.w, shown.h, iw, ih, view, selectedLive, measure]);
// -- editing -------------------------------------------------------------
const apply = useCallback((next: Op[]) => {
@@ -393,7 +426,15 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
setDirty(true);
}, []);
- const push = useCallback((shape: Draft) => apply([...history.present, withId(shape)]), [apply, history.present]);
+ /** Add a shape; its id, so a fresh annotation can be selected at once. */
+ const push = useCallback(
+ (shape: Draft) => {
+ const op = withId(shape);
+ apply([...history.present, op]);
+ return op.id;
+ },
+ [apply, history.present],
+ );
const undo = useCallback(() => {
setHistory(undoHistory);
@@ -463,6 +504,31 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
if (!image || event.button !== 0) return;
const p = toImage(event);
if (tool === "background") return;
+ if (tool !== "crop") {
+ // Every annotation can be taken by the hand, whatever tool is active:
+ // a grip of the selected one reshapes it, the annotation itself moves.
+ if (selected && selectedLive) {
+ const grip = handleAt(selectedLive, p, (GRIP_RADIUS + 4) / scale, measure);
+ if (grip) {
+ event.preventDefault();
+ event.currentTarget.setPointerCapture?.(event.pointerId);
+ setGesture({ kind: "resize", id: selected.id, handle: grip, original: selected, at: p });
+ return;
+ }
+ }
+ // Spotlights and redactions cover what lies in them, so only the
+ // select tool picks them; with a drawing tool they stay drawable on.
+ const hit = hitTest(ops, p, 6 / scale, measure, { areas: tool === "move" });
+ if (hit && !(tool === "text" && hit.kind === "text")) {
+ event.preventDefault();
+ if (typing) commitText();
+ event.currentTarget.setPointerCapture?.(event.pointerId);
+ setSelectedId(hit.id);
+ setGesture({ kind: "move", id: hit.id, start: p, dx: 0, dy: 0 });
+ return;
+ }
+ setSelectedId(null);
+ }
if (tool === "text") {
// Keep the press from moving focus away: it would blur (and so close)
// the text box this click is about to open.
@@ -472,16 +538,11 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
return;
}
if (tool === "counter") {
- push({ kind: "counter", at: p, n: nextCounter(ops), color, size: counterSize(width) });
+ setSelectedId(push({ kind: "counter", at: p, n: nextCounter(ops), color, size: counterSize(width) }));
return;
}
event.currentTarget.setPointerCapture?.(event.pointerId);
- if (tool === "move") {
- const hit = hitTest(ops, p, 6 / scale, measure);
- setSelectedId(hit?.id ?? null);
- if (hit) setGesture({ kind: "move", id: hit.id, start: p, dx: 0, dy: 0 });
- return;
- }
+ if (tool === "move") return;
const zero = { x: p.x, y: p.y, w: 0, h: 0 };
let shape: Draft;
switch (tool) {
@@ -514,8 +575,20 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
const onPointerMove = (event: React.PointerEvent<HTMLCanvasElement>) => {
const current = gestureRef.current;
- if (!current) return;
const p = toImage(event);
+ if (!current) {
+ // Say with the pointer what a press here would do: reshape, move, or draw.
+ if (!image || tool === "crop" || tool === "background") return setHoverCursor(null);
+ const grip = selectedLive ? handleAt(selectedLive, p, (GRIP_RADIUS + 4) / scale, measure) : null;
+ if (grip) return setHoverCursor(handleCursor(grip));
+ const hit = hitTest(ops, p, 6 / scale, measure, { areas: tool === "move" });
+ setHoverCursor(hit && !(tool === "text" && hit.kind === "text") ? "move" : null);
+ return;
+ }
+ if (current.kind === "resize") {
+ setGesture({ ...current, at: p });
+ return;
+ }
if (current.kind === "move") {
setGesture({ ...current, dx: p.x - current.start.x, dy: p.y - current.start.y });
return;
@@ -533,6 +606,12 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
const current = gestureRef.current;
if (!current) return;
setGesture(null);
+ if (current.kind === "resize") {
+ const reshaped = reshape(current.original, current.handle, current.at, measure);
+ if ("rect" in reshaped && (reshaped.rect.w < 2 || reshaped.rect.h < 2)) return;
+ apply(ops.map((op) => (op.id === current.id ? reshaped : op)));
+ return;
+ }
if (current.kind === "move") {
if (current.dx !== 0 || current.dy !== 0) {
apply(ops.map((op) => (op.id === current.id ? translate(op, current.dx, current.dy) : op)));
@@ -546,8 +625,10 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
shape = { ...shape, rect } as Draft;
}
if (!isMeaningful(shape)) return;
- push(shape);
+ const id = push(shape);
if (shape.kind === "crop") setTool("move");
+ // A fresh annotation is selected at once, so its grips are right there.
+ else setSelectedId(id);
};
const onDoubleClick = (event: React.MouseEvent<HTMLCanvasElement>) => {
@@ -757,8 +838,14 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
const textScreen = typing
? { left: (typing.at.x - shown.x) * scale, top: (typing.at.y - shown.y) * scale }
: null;
+ const toolCursor =
+ tool === "text" ? "text" : tool === "move" || tool === "background" ? "default" : "crosshair";
const cursor =
- tool === "text" ? "text" : tool === "move" ? (gesture?.kind === "move" ? "grabbing" : "default") : tool === "background" ? "default" : "crosshair";
+ gesture?.kind === "move"
+ ? "grabbing"
+ : gesture?.kind === "resize"
+ ? handleCursor(gesture.handle)
+ : hoverCursor ?? toolCursor;
const frameOn = framing.enabled;
const preset = presetById(background.preset);
const zoomLabel = zoom === "fit" ? label("zoom_fit") : `${Math.round(zoom * 100)}%`;
@@ -1089,6 +1176,7 @@ export function AppshotEditor({ appshotId, onClose, onApplied, variant = "overla
onPointerMove={onPointerMove}
onPointerUp={onPointerUp}
onPointerCancel={() => setGesture(null)}
+ onPointerLeave={() => setHoverCursor(null)}
onDoubleClick={onDoubleClick}
data-testid="appshot-editor-canvas"
/>