Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .agents/skills/verify-screens/features/camera-focus.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A person pans with Hand, Shift-drag, the middle button or the wheel. They zoom w
## Sub-features

- `cam-pan`: Hand, Shift-drag and the wheel pan by the screen delta, with no revision.
- `shift-pan-page`: Shift-drag pans at once after a click inside a selected live page, which takes keyboard focus. Releasing Shift gives the page the pointer again.
- `minimap`: the map is off by default. Turn it on to see the canvas and navigate by click or drag. The choice survives a reload.
- `cam-zoom`: zoom out and in around the centre; Cmd+0 goes to 100%; Fit all frames everything and turns auto-fit back on.
- `zoom-preview`: background boards use a preview at their current size during zoom. The selected board stays live.
Expand Down Expand Up @@ -48,6 +49,17 @@ drag @A.title by 40,0
expect doc.@A.x=40 doc.rev=+1 storage.rev=doc.rev
```

```screens id=shift-pan-page
add_object title=A files=fixture:plain x=0 y=0 width=800 height=600 as=@A
zoom 100
click @A
inside @A click body
expect view.interacting=@A frames.@A.input=page
mark
drag @A by 60,0 --shift
expect view.camera.x=+60 doc.@A.x=0 doc.rev=+0 view.shiftPanning=false frames.@A.input=page
```

```screens id=cam-zoom
add_object title=A files=fixture:plain x=0 y=0 height=300 as=@A
zoom 100
Expand Down
10 changes: 6 additions & 4 deletions packages/canvas/src/engine/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export type CanvasInput =
| { readonly type: "key-down"; readonly key: string; readonly code: string; readonly mod: boolean; readonly shift: boolean; readonly editable: boolean; readonly control: boolean }
| { readonly type: "key-up"; readonly code: string }
| { readonly type: "window-blur"; readonly activeFrameItem: ItemId | null }
| { readonly type: "bridge"; readonly itemId: ItemId; readonly msg: { readonly kind: "pointer"; readonly x: number; readonly y: number } | { readonly kind: "zoom"; readonly x: number; readonly y: number; readonly dy: number; readonly pinch: boolean } | { readonly kind: "pan"; readonly dx: number; readonly dy: number } | { readonly kind: "escape" } }
| { readonly type: "bridge"; readonly itemId: ItemId; readonly msg: { readonly kind: "pointer"; readonly x: number; readonly y: number } | { readonly kind: "zoom"; readonly x: number; readonly y: number; readonly dy: number; readonly pinch: boolean } | { readonly kind: "pan"; readonly dx: number; readonly dy: number } | { readonly kind: "escape" } | { readonly kind: "shift"; readonly down: boolean } }
| { readonly type: "tick"; readonly now: number }
| { readonly type: "camera-settled" }
| { readonly type: "resize"; readonly viewport: Size }
Expand Down Expand Up @@ -298,6 +298,8 @@ function stepInner(s: ViewState, input: CanvasInput, doc: BaseDoc, env: Env, fx:
if (!it) return s;
const m = input.msg;
if (m.kind === "pointer") return s.tool === "move" ? { ...s, interacting: input.itemId } : s;
// Shift pressed while a live page has keyboard focus. A focused page keeps Shift for selecting its own pieces.
if (m.kind === "shift") return presenting(s, doc) || (s.focus.mode === "focused" && s.focus.itemId === input.itemId) ? s : { ...s, shiftPanning: m.down };
if (m.kind === "escape") {
fx.push({ type: "blur-active" });
const n = { ...s, interacting: null };
Expand Down Expand Up @@ -1122,8 +1124,8 @@ export interface FramePresentation {
readonly hiddenByFocus: boolean; readonly input: "shield" | "page"; readonly showActions: boolean;
}
/**
* The page takes pointer input only when it is a ready live snapshot and it is interacting, or the Move tool is
* active without Shift and it is the sole selection or the focused item. Everything else gets the shield.
* The page takes pointer input only when it is a ready live snapshot, Shift is not held, and it is interacting or the
* Move tool is active and it is the sole selection or the focused item. Everything else gets the shield.
*/
export function presentFrame(item: { readonly id: ItemId; readonly kind: string; readonly width: number; readonly removing: boolean }, s: ViewState, ready: boolean): FramePresentation {
const ids = selectedIds(s);
Expand All @@ -1132,7 +1134,7 @@ export function presentFrame(item: { readonly id: ItemId; readonly kind: string;
const focused = focusedId === item.id;
// Only the scroll view (every canvas is in it) lets a page take input: in the grid a press reorders or opens, and Present steps.
const page = item.kind === "html-snapshot" && ready && !item.removing && s.gesture === null && s.pages.view === "scroll" &&
(s.interacting === item.id || (s.tool === "move" && !s.shiftPanning && ((selected && ids.length === 1) || focused)));
!s.shiftPanning && (s.interacting === item.id || (s.tool === "move" && ((selected && ids.length === 1) || focused)));
return {
selected: selected && ids.length === 1, multiSelected: selected && ids.length > 1, interacting: s.interacting === item.id, focused,
hiddenByFocus: focusedId !== null && !focused, input: page ? "page" : "shield",
Expand Down
1 change: 1 addition & 0 deletions packages/canvas/src/shell/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ export class CanvasRuntime {
else if (d.kind === "zoom") this.dispatch({ type: "bridge", itemId: host.itemId, msg: { kind: "zoom", x: Number(d.x), y: Number(d.y), dy: Number(d.dy), pinch: d.pinch === true } });
else if (d.kind === "pan") this.dispatch({ type: "bridge", itemId: host.itemId, msg: { kind: "pan", dx: Number(d.dx) || 0, dy: Number(d.dy) || 0 } });
else if (d.kind === "escape") this.dispatch({ type: "bridge", itemId: host.itemId, msg: { kind: "escape" } });
else if (d.kind === "shift") this.dispatch({ type: "bridge", itemId: host.itemId, msg: { kind: "shift", down: d.down === true } });
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/frames/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ else if(d.kind==="text")parent.postMessage({kind:"text",gen,pid:pid(d.pid),text:
else if(d.kind==="move")parent.postMessage({kind:"move",gen,items:Array.isArray(d.items)?d.items.slice(0,50).map((m)=>m&&typeof m==="object"?{pid:pid(m.pid),rel:m.rel===true,x:opt(m.x),y:opt(m.y),w:opt(m.w),h:opt(m.h)}:null).filter((m)=>m&&m.pid):[]},to);
else if(d.kind==="zoom")parent.postMessage({kind:"zoom",gen,x:num(d.x),y:num(d.y),dy:num(d.dy),pinch:d.pinch===true},to);
else if(d.kind==="pan")parent.postMessage({kind:"pan",gen,dx:num(d.dx),dy:num(d.dy)},to);
else if(d.kind==="shift")parent.postMessage({kind:"shift",gen,down:d.down===true},to);
else if(d.kind==="escape")parent.postMessage({kind:"escape",gen},to);});})();</script></body></html>`;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/frames/src/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,14 @@ const k=e.deltaMode===1?16:e.deltaMode===2?innerHeight:1,dx=e.deltaX*k,dy=e.delt
addEventListener("keydown",(e)=>{if(ed){e.stopPropagation();if(e.key==="Escape"){e.preventDefault();finish(false)}else if(e.key==="Enter"&&!e.shiftKey){e.preventDefault();finish(true)}return}
// A form control or the page's own editable text keeps its keys: arrows move its caret and undo is its own.
const t=e.target;if(t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))){if(e.key==="Escape")p({kind:"escape"});return}
// Shift held over the canvas pans it. The canvas cannot see keys pressed in here, so the page reports Shift.
if(e.key==="Shift"&&!e.repeat){p({kind:"shift",down:true});return}
// Arrow keys nudge the selection, ten pixels with Shift. A run of presses is reported once it pauses, as one move.
const dir={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];
if(dir&&sel.length&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault();e.stopPropagation();const k=e.shiftKey?10:1;
if(!nudged)nudged={list:starts(),x:0,y:0};nudged.x+=dir[0]*k;nudged.y+=dir[1]*k;for(const s of nudged.list)put(s,s.l+nudged.x,s.t+nudged.y);box();
clearTimeout(nudgeTimer);nudgeTimer=setTimeout(()=>{const n=nudged;nudged=null;if(n&&n.list.length)report(n.list)},350);return}
// The person's undo and redo belong to the canvas, which cannot see keys pressed in here.
if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="z"){e.preventDefault();p({kind:"history",redo:e.shiftKey});return}
if(e.key==="Escape")p({kind:"escape"})},true);})();`;
if(e.key==="Escape")p({kind:"escape"})},true);
addEventListener("keyup",(e)=>{if(e.key==="Shift")p({kind:"shift",down:false})},true);})();`;