mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-27 17:01:38 +01:00
M5: исправить адресное управление прототипами
Сохранять явный выбор документа при адресных вызовах и вложенных пакетах. Откатывать запросы интерфейсу отказавшей группы, сохраняя обычные диалоги. Распознавать оба имени стрелок и показывать предпросмотр поверх редактора. Добавить воспроизводящие тесты и уточнить документацию протокола. По замечаниям сопровождающего перевести новые комментарии и пояснения тестов на английский. Перенести изменение поверх актуальной main без коммита слияния, сохранив обе записи состояния: сначала нашу, затем записи основной ветки.
This commit is contained in:
1 parent
b45255bb6f
commit
b85b944df3
19 files changed
+287
-13
No files matched your search
+2
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
**Stage: alpha** · next: beta, ~26 points and ~162–292 h away (one Opus 5.5 agent; ~33–67 h wall-clock with 5 agents)
|
||||
|
||||
> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-19 · **Change:** minor (code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); library analytics count insertions and detachments of styles and variables; web builds with craft-fonts embed Noto Sans Arabic by default so Persian and Arabic text draws without extra build flags (#1902); the browser build uses team libraries and plugin directories on a server; CLI post-parse errors escape terminal controls in paths and failure text; M6 `.fig` export writes text on a path (#2323), list spacing, hanging punctuation and lists, vertical trim (#2305), vector region paints (#2302), image adjustments (#2297) and a page's prototype background (#2326); M8 Tidy up keeps a row's or column's order and sizes and evens the gaps, rounds the gap, tidies overlapping rows and grids along their longer axis, and raises a negative gap so no layer reaches the one two before it, as measured in Figma (#2319); a polygon's or star's Count handle and a double-click on a layer's icon (zoom, range anchor) follow Figma; Tab while renaming moves only the rename and wraps from the last layer; Align is unavailable for a layer in an auto layout frame's flow; the Scale tool pivots on the opposite handle and starts its origin at the centre; Paste over selection puts the copies just above the selected layer; Crop from the image fill's menu crops with a drag (#2307); M10 code export writes every colour and gradient fill in paint order for CSS, SwiftUI, Compose and Flutter (#2271), CSS as one layered background; 24 pt icon buttons draw 16 pt glyphs (#2227, #2238); M5 marquee selection follows Figma's measured rules and Select layer lists locked layers with a padlock (#1560); M7 the Design panel shows the page's variable modes with nothing selected (#2215); M12 mind maps in a section or frame without a place centre on the view, stickies take a Small–Huge text-size menu, and M9 `.jam` shapes with text import as native board shapes (#1808); M4 a boolean group's corner radius rounds its result (#2222), Flatten bakes a point's corner radius into its path (#2195) and loops close through a joining segment (#1951); library links survive moving or cloning the project folder (#2132); renaming a variable group to a path with `/` nests it (#2353); SVG import, widget images, batches and grids take bounded work, and a host's server key is never sent over plain `ws://` to another machine (#1923); CI prefetches dependencies for Sonar coverage and runs Harden-Runner on every job; releases FigCraft v0.18.0 and v0.18.1 (Flatpak update fix); readiness estimates unchanged) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-19 · **Change:** minor (M5: prototype arrow-key aliases and explicit document-scoped player controls, including batch rollback; numbers unchanged; code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); library analytics count insertions and detachments of styles and variables; web builds with craft-fonts embed Noto Sans Arabic by default so Persian and Arabic text draws without extra build flags (#1902); the browser build uses team libraries and plugin directories on a server; CLI post-parse errors escape terminal controls in paths and failure text; M6 `.fig` export writes text on a path (#2323), list spacing, hanging punctuation and lists, vertical trim (#2305), vector region paints (#2302), image adjustments (#2297) and a page's prototype background (#2326); M8 Tidy up keeps a row's or column's order and sizes and evens the gaps, rounds the gap, tidies overlapping rows and grids along their longer axis, and raises a negative gap so no layer reaches the one two before it, as measured in Figma (#2319); a polygon's or star's Count handle and a double-click on a layer's icon (zoom, range anchor) follow Figma; Tab while renaming moves only the rename and wraps from the last layer; Align is unavailable for a layer in an auto layout frame's flow; the Scale tool pivots on the opposite handle and starts its origin at the centre; Paste over selection puts the copies just above the selected layer; Crop from the image fill's menu crops with a drag (#2307); M10 code export writes every colour and gradient fill in paint order for CSS, SwiftUI, Compose and Flutter (#2271), CSS as one layered background; 24 pt icon buttons draw 16 pt glyphs (#2227, #2238); M5 marquee selection follows Figma's measured rules and Select layer lists locked layers with a padlock (#1560); M7 the Design panel shows the page's variable modes with nothing selected (#2215); M12 mind maps in a section or frame without a place centre on the view, stickies take a Small–Huge text-size menu, and M9 `.jam` shapes with text import as native board shapes (#1808); M4 a boolean group's corner radius rounds its result (#2222), Flatten bakes a point's corner radius into its path (#2195) and loops close through a joining segment (#1951); library links survive moving or cloning the project folder (#2132); renaming a variable group to a path with `/` nests it (#2353); SVG import, widget images, batches and grids take bounded work, and a host's server key is never sent over plain `ws://` to another machine (#1923); CI prefetches dependencies for Sonar coverage and runs Harden-Runner on every job; releases FigCraft v0.18.0 and v0.18.1 (Flatpak update fix); readiness estimates unchanged) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
FigCraft is a clean-room, open-source, pure-Rust reimplementation of the Figma design workflow,
|
||||
native on macOS, Windows, Linux and FreeBSD and in the browser, fully drivable by agents through
|
||||
@@ -366,6 +366,7 @@ Ranked; detail and milestones in [`docs/roadmap.md`](docs/roadmap.md).
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-15 | patch | M5: prototype arrow aliases match platform key names; explicit document selection survives addressed calls and nested batches; failed commands and groups discard their queued UI effects. Readiness numbers unchanged. |
|
||||
| 2026-11-18 | minor | M8: design context for AI agents. `inspect.designContext` and the MCP tool `design_context` read the selection (or `ids`, or a `scope`) in one call: a tree where each layer keeps apart `explicit` values, `derived` ones layout worked out and `unsupported` ones with no direct CSS equivalent, joined with the variables (every mode's stored and resolved value), styles, components, fonts and assets it uses, and what the design leaves `missing`. A connected instance gives its code instead of its layers, and a result that wouldn't fit the client asks for fewer layers. Numbers unchanged |
|
||||
| 2026-11-18 | minor | M3, gap 10: library analytics count insertions and detachments of styles and variables. Applying one, or copying or duplicating content that uses it, inserts it; the Detach button detaches it; an instance counts as its component alone. Show usage and `library.usage` give them per style and variable over the chosen period. Modes aren't counted. Numbers unchanged. Tests: `library_asset_counts_tests`, `library_assets_tests`. |
|
||||
| 2026-11-18 | minor | M9, gap 6: the browser build uses team libraries and plugin directories on a server, through its WebSocket requests: adding a library by its link, its styles and components, publishing to it, Show usage and the reports a file sends; browsing a directory and installing from it, for the page only. Scripts through `window.figcraft` still can't, as commands there don't wait for the server. Numbers unchanged. Tests: `exchange_tests`. |
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
# To remove your names, delete your entry (or set fields empty) in a PR. The next
|
||||
# contributors.py run, and the next build, drop them.
|
||||
|
||||
[people.varvbudi-netizen]
|
||||
sync_github_name = true
|
||||
|
||||
[people.VanTan666]
|
||||
display_name = "VanTan"
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@ impl Trigger {
|
||||
pub fn fires_on_key(&self, key: &str, mods: KeyMods) -> bool {
|
||||
let Trigger::KeyPress { key: want } = self else { return false };
|
||||
let (m, k) = KeyMods::split(want);
|
||||
m == mods && (k.eq_ignore_ascii_case(key) || key_alias(k) == Some(key))
|
||||
// The window uses Right while saved prototypes use ArrowRight; normalize both sides.
|
||||
m == mods && (k.eq_ignore_ascii_case(key) || key_alias(k).is_some_and(|alias| key_alias(key) == Some(alias)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ pub use view_state::ViewState;
|
||||
pub struct Session {
|
||||
pub docs: Vec<DocState>,
|
||||
pub active: usize,
|
||||
/// Explicit file-selection revision; command rollback restores it along with the selection.
|
||||
document_selection_revision: u64,
|
||||
pub clipboard: Clipboard,
|
||||
/// Edit ▸ Set default properties: what new shapes and text drawn with the tools take.
|
||||
pub default_props: DefaultProps,
|
||||
|
||||
@@ -62,6 +62,13 @@ fn key_triggers_fire_for_their_key_or_combination() {
|
||||
("space", "Space", none, true, "names in any case"),
|
||||
("Return", "Enter", none, true, "common other names of keys"),
|
||||
("←", "ArrowLeft", none, true, "arrow glyphs"),
|
||||
// Window names, saved names and arrow glyphs are equivalent in both directions.
|
||||
("ArrowRight", "Right", none, true, "saved arrow and egui key name"),
|
||||
("Left", "ArrowLeft", none, true, "reverse alias matching"),
|
||||
("↑", "Up", none, true, "arrow glyph and window key name"),
|
||||
("Shift+ArrowDown", "Down", shift, true, "arrow with a modifier"),
|
||||
("Shift+ArrowDown", "Down", none, false, "the modifier is still required"),
|
||||
("ArrowRight", "Left", none, false, "different directions do not match"),
|
||||
("Shift+Space", "Space", shift, true, "a named key in a combination"),
|
||||
("J", "K", none, false, "another key"),
|
||||
];
|
||||
|
||||
@@ -5,9 +5,20 @@ use super::{DocState, Document, EngineError, NodeId, Result, Session, Value, jso
|
||||
pub struct Forward {
|
||||
target: u64,
|
||||
shown: Option<u64>,
|
||||
selection_revision: u64,
|
||||
}
|
||||
|
||||
impl Session {
|
||||
/// Explicit file or prototype selection keeps the selected tab in front after a targeted call.
|
||||
pub(super) fn command_shows_document(command: &str) -> bool {
|
||||
matches!(command, "file.new" | "file.open" | "doc.switch" | "doc.nextTab" | "doc.previousTab" | "proto.present" | "proto.preview")
|
||||
}
|
||||
|
||||
/// Lets the UI distinguish explicit file selection from temporary request routing.
|
||||
pub fn document_selection_revision(&self) -> u64 {
|
||||
self.document_selection_revision
|
||||
}
|
||||
|
||||
/// The uid of open file `target`: its `id` (from `doc.list` or `document.inspect`) or its path.
|
||||
pub fn document_uid(&self, target: &Value) -> Result<u64> {
|
||||
let found = match target {
|
||||
@@ -28,13 +39,14 @@ impl Session {
|
||||
if let Some(i) = self.docs.iter().position(|d| d.uid == uid) {
|
||||
self.active = i;
|
||||
}
|
||||
Ok(Forward { target: uid, shown })
|
||||
Ok(Forward { target: uid, shown, selection_revision: self.document_selection_revision })
|
||||
}
|
||||
|
||||
/// Bring back the tab that was in front before [`Session::bring_forward`], unless the request
|
||||
/// itself moved the front to another open file (`file.open`, `doc.switch`…), as it would have.
|
||||
pub fn put_back(&mut self, f: Forward) {
|
||||
let moved = self.docs.iter().any(|d| d.uid == f.target) && self.ds().ok().map(|d| d.uid) != Some(f.target);
|
||||
let selected = self.document_selection_revision != f.selection_revision;
|
||||
let moved = selected || (self.docs.iter().any(|d| d.uid == f.target) && self.ds().ok().map(|d| d.uid) != Some(f.target));
|
||||
if let Some(i) = f.shown.and_then(|u| self.docs.iter().position(|d| d.uid == u)).filter(|_| !moved) {
|
||||
self.active = i;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,8 @@ impl Session {
|
||||
let before = self.ds().ok().map(|d| (d.doc.clone(), d.selection.clone(), d.page, d.uid));
|
||||
// Cut and copy write the clipboard before a later check can refuse the command.
|
||||
let clipboard_before = self.clipboard.clone();
|
||||
// A failed command must not count a document selection made by a nested batch.
|
||||
let selection_revision_before = self.document_selection_revision;
|
||||
// An inner command of a batch can panic while the outer group is still open; remember the
|
||||
// context so the panic does not clear the group's buffered events.
|
||||
let group_depth_before = self.group_depth;
|
||||
@@ -141,6 +143,7 @@ impl Session {
|
||||
ds.page = page;
|
||||
}
|
||||
self.clipboard = clipboard_before;
|
||||
self.document_selection_revision = selection_revision_before;
|
||||
}
|
||||
}
|
||||
self.after_comment_command(id, params, &result, group_depth_before, pending_events_before);
|
||||
@@ -241,6 +244,10 @@ impl Session {
|
||||
|
||||
/// Bookkeeping after a successful command (normalised already): push undo, bump revision.
|
||||
fn after_command(&mut self, spec: &CommandSpec, before: Option<(Arc<Document>, Vec<NodeId>, NodeId, u64)>) {
|
||||
// Count executed commands, including nested ones; scanning input JSON cannot account for failures.
|
||||
if Self::command_shows_document(spec.id) {
|
||||
self.document_selection_revision = self.document_selection_revision.wrapping_add(1);
|
||||
}
|
||||
let Some((bdoc, bsel, bpage, uid)) = before else {
|
||||
if let Ok(ds) = self.ds_mut() {
|
||||
ds.revision += 1;
|
||||
|
||||
@@ -13,6 +13,7 @@ impl Session {
|
||||
Self {
|
||||
docs: Vec::new(),
|
||||
active: 0,
|
||||
document_selection_revision: 0,
|
||||
clipboard: Clipboard::default(),
|
||||
default_props: Default::default(),
|
||||
prefs: Prefs::default(),
|
||||
|
||||
@@ -22,6 +22,8 @@ struct GroupCheckpoint {
|
||||
journal_len: usize,
|
||||
/// Live events buffered before the group: a failed one drops only its own.
|
||||
pending_events: usize,
|
||||
ui_requests: usize,
|
||||
document_selection_revision: u64,
|
||||
last_command: Option<(String, Value)>,
|
||||
}
|
||||
|
||||
@@ -341,6 +343,8 @@ impl Session {
|
||||
active: self.active,
|
||||
journal_len: self.journal.len(),
|
||||
pending_events: self.pending_events.len(),
|
||||
ui_requests: self.ui_requests.len(),
|
||||
document_selection_revision: self.document_selection_revision,
|
||||
last_command: self.last_command.clone(),
|
||||
};
|
||||
// The steps inside are dropped again below, so they mustn't push the oldest ones out.
|
||||
@@ -381,6 +385,9 @@ impl Session {
|
||||
self.active = before.active;
|
||||
self.journal.truncate(before.journal_len);
|
||||
self.pending_events.truncate(before.pending_events);
|
||||
// UI requests are deferred group effects, just like collaboration events.
|
||||
self.ui_requests.truncate(before.ui_requests);
|
||||
self.document_selection_revision = before.document_selection_revision;
|
||||
if restore_last_command {
|
||||
self.last_command = before.last_command;
|
||||
}
|
||||
|
||||
@@ -364,3 +364,42 @@ impl Backend for Headless {
|
||||
figcraft_render::encode_png(&pix)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod document_tests {
|
||||
use super::{Backend, Headless};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn explicit_switch_survives_document_routing_but_edits_and_errors_do_not_switch() {
|
||||
// Headless routing preserves the same file-selection behavior as an attached app.
|
||||
let mut backend = Headless::default();
|
||||
let back = backend.session.docs[0].uid;
|
||||
backend.call("engine.execute", json!({"command": "file.new", "params": {}})).unwrap();
|
||||
backend.call("engine.execute", json!({"command": "frame.create", "document": back, "params": {"width": 200, "height": 200}})).unwrap();
|
||||
assert_eq!(backend.session.active, 1);
|
||||
assert!(backend.call("engine.execute", json!({"command": "doc.switch", "document": back, "params": {"index": 999}})).is_err());
|
||||
assert_eq!(backend.session.active, 1);
|
||||
backend.call("engine.execute", json!({"command": "doc.switch", "document": back, "params": {"index": 0}})).unwrap();
|
||||
assert_eq!(backend.session.active, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_batches_track_only_successful_document_switches() {
|
||||
// Nested commands use the same selection tracking as a direct call.
|
||||
let switch = json!({"command": "doc.switch", "params": {"index": 0}});
|
||||
let failed = json!({"command": "command.batch", "params": {"commands": [switch, {"command": "does.not.exist"}]}});
|
||||
for (params, expected) in [
|
||||
(json!({"commands": [switch]}), 0usize),
|
||||
(json!({"commands": [{"command": "command.batch", "params": {"commands": [switch]}}]}), 0),
|
||||
(json!({"onError": "continue", "commands": [failed]}), 1),
|
||||
(json!({"onError": "continue", "commands": [{"command": "doc.switch", "params": {"index": 999}}]}), 1),
|
||||
] {
|
||||
let mut backend = Headless::default();
|
||||
let back = backend.session.docs[0].uid;
|
||||
backend.call("engine.execute", json!({"command": "file.new", "params": {}})).unwrap();
|
||||
backend.call("engine.execute", json!({"document": back, "command": "command.batch", "params": params})).unwrap();
|
||||
assert_eq!(backend.session.active, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ const DOCUMENT_TOOLS: &[&str] = &[
|
||||
pub fn tool_definitions() -> Vec<Value> {
|
||||
let mut tools = tools();
|
||||
let document = id_schema(
|
||||
"The open file to act on: its `id` (from run_command doc.list, or the `document` open_file and inspect_document return) or its path. Default: the file in front. The tab in front stays in front; with an attached app, a screenshot of the window needs the file in front",
|
||||
"The open file to act on: its `id` (from run_command doc.list, or the `document` open_file and inspect_document return) or its path. Default: the file in front. Reads and edits keep the front tab; explicit file/tab switches and proto.present/proto.preview show the requested file. With an attached app, a screenshot of the window needs the file in front",
|
||||
);
|
||||
for t in &mut tools {
|
||||
if t.get("name").and_then(Value::as_str).is_some_and(|n| DOCUMENT_TOOLS.contains(&n))
|
||||
|
||||
@@ -224,6 +224,9 @@ impl FigApp {
|
||||
}
|
||||
"preview" => {
|
||||
if let Some(start) = r.data.get("start").and_then(figcraft_engine::params::id_of) {
|
||||
// The preview draws over the editor and must not stay behind the presenter.
|
||||
tabs::pause_present(self);
|
||||
self.ui.home = false;
|
||||
self.ui.preview = Some(present::Pane::new(start, &self.session));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1469,7 +1469,13 @@ pub fn handle(app: &mut FigApp, ctx: &Context, method: &str, p: &Value) -> Resul
|
||||
let params = p.get("params").cloned().unwrap_or(json!({}));
|
||||
let layers_generation = app.session.clipboard.layers_generation;
|
||||
let agent = p.get("agent").and_then(Value::as_str);
|
||||
let selection_before = app.session.document_selection_revision();
|
||||
let r = in_document(app, p, |s| s.execute_as(agent, cmd, ¶ms).map_err(|e| e.to_string()));
|
||||
// Like clicking a tab, explicitly selecting a file moves the presenter out of the foreground.
|
||||
if r.is_ok() && app.session.document_selection_revision() != selection_before {
|
||||
crate::tabs::pause_present(app);
|
||||
app.ui.home = false;
|
||||
}
|
||||
app.clear_comment_draft_after_tool_set(cmd, r.is_ok());
|
||||
app.invalidate_synthetic_copy(layers_generation);
|
||||
// Programmatic calls never open dialogs.
|
||||
|
||||
@@ -60,3 +60,165 @@ fn a_command_that_opens_a_file_still_brings_it_to_the_front() {
|
||||
handle(&mut app, "engine.execute", json!({"command": "file.new", "document": back})).unwrap();
|
||||
assert_eq!(app.session.active, 2, "a new file opens in front");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicitly_switching_to_the_named_document_keeps_it_in_front() {
|
||||
// Selecting a file temporarily brought forward still counts as an explicit switch.
|
||||
let (mut app, back) = two_files();
|
||||
handle(&mut app, "engine.execute", json!({"command": "doc.switch", "params": {"index": 0}, "document": back})).unwrap();
|
||||
assert_eq!(app.session.active, 0);
|
||||
assert!(!app.ui.home);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_foreground_command_leaves_the_front_document_in_place() {
|
||||
// A failed targeted command must not switch the user to another file.
|
||||
let (mut app, back) = two_files();
|
||||
for (command, params) in
|
||||
[("doc.switch", json!({"index": 999})), ("proto.present", json!({"start": 999})), ("proto.preview", json!({"start": 999}))]
|
||||
{
|
||||
assert!(handle(&mut app, "engine.execute", json!({"command": command, "params": params, "document": back})).is_err());
|
||||
assert_eq!(app.session.active, 1);
|
||||
assert!(app.ui.present.is_none());
|
||||
assert!(app.ui.preview.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn presenting_a_named_document_uses_its_frames_and_retargets_the_player() {
|
||||
// Identical layer IDs in different files must not mix up their prototypes.
|
||||
let (mut app, back) = two_files();
|
||||
let create = |app: &mut FigApp, document: u64, name: &str| {
|
||||
handle(app, "engine.execute", json!({"document": document, "command": "frame.create", "params": {"name": name, "width": 200, "height": 200}}))
|
||||
.unwrap()["id"]
|
||||
.clone()
|
||||
};
|
||||
let front = app.session.docs[1].uid;
|
||||
let front_frame = create(&mut app, front, "Front frame");
|
||||
let back_frame = create(&mut app, back, "Back frame");
|
||||
let back_second = create(&mut app, back, "Back second");
|
||||
assert_eq!(front_frame, back_frame, "exercise colliding frame IDs");
|
||||
for (document, start, owner) in [(front, front_frame, 1), (back, back_frame, 0), (back, back_second, 0)] {
|
||||
handle(&mut app, "engine.execute", json!({"document": document, "command": "proto.present", "params": {"start": start}})).unwrap();
|
||||
assert_eq!(app.session.active, owner);
|
||||
assert_eq!(app.ui.present.as_ref().unwrap().start().0, start.as_u64().unwrap());
|
||||
let active = app.ui.present_active.unwrap();
|
||||
assert_eq!(app.ui.presents.iter().find(|t| t.id == active).unwrap().doc_uid, document);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_opens_on_the_requested_file_instead_of_behind_its_presenter() {
|
||||
let (mut app, back) = two_files();
|
||||
let frame = handle(&mut app, "engine.execute", json!({"document": back, "command": "frame.create", "params": {"width": 200, "height": 200}}))
|
||||
.unwrap()["id"]
|
||||
.clone();
|
||||
app.session.active = 0;
|
||||
handle(&mut app, "engine.execute", json!({"command": "proto.present", "params": {"start": frame}})).unwrap();
|
||||
assert!(app.ui.present.is_some());
|
||||
handle(&mut app, "engine.execute", json!({"document": back, "command": "proto.preview", "params": {"start": frame}})).unwrap();
|
||||
assert!(app.ui.present.is_none(), "the preview must be visible");
|
||||
assert!(app.ui.preview.is_some());
|
||||
assert_eq!(app.session.active, 0);
|
||||
assert!(!app.ui.home);
|
||||
|
||||
// Setting the UI state must produce the same result as executing the command.
|
||||
handle(&mut app, "engine.execute", json!({"command": "proto.present", "params": {"start": frame}})).unwrap();
|
||||
handle(&mut app, "ui.set", json!({"preview": frame})).unwrap();
|
||||
assert!(app.ui.present.is_none());
|
||||
assert!(app.ui.preview.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_batch_present_request_keeps_its_document_for_the_ui() {
|
||||
// A batch passes its request to the UI after executing the nested steps.
|
||||
let (mut app, back) = two_files();
|
||||
let frame = handle(&mut app, "engine.execute", json!({"document": back, "command": "frame.create", "params": {"width": 200, "height": 200}}))
|
||||
.unwrap()["id"]
|
||||
.clone();
|
||||
handle(
|
||||
&mut app,
|
||||
"engine.execute",
|
||||
json!({"document": back, "command": "command.batch", "params": {"commands": [{"command": "proto.present", "params": {"start": frame}}]}}),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(app.session.active, 0);
|
||||
assert!(app.ui.present.is_some());
|
||||
let active = app.ui.present_active.unwrap();
|
||||
assert_eq!(app.ui.presents.iter().find(|t| t.id == active).unwrap().doc_uid, back);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_batches_track_only_successful_document_switches() {
|
||||
// A failed nested batch with continue must not count as a completed switch.
|
||||
let switch = json!({"command": "doc.switch", "params": {"index": 0}});
|
||||
let failed = json!({"command": "command.batch", "params": {"commands": [switch, {"command": "does.not.exist"}]}});
|
||||
for (params, expected) in [
|
||||
(json!({"commands": [switch]}), 0usize),
|
||||
(json!({"commands": [{"command": "command.batch", "params": {"commands": [switch]}}]}), 0),
|
||||
(json!({"onError": "continue", "commands": [failed]}), 1),
|
||||
(json!({"onError": "continue", "commands": [{"command": "doc.switch", "params": {"index": 999}}]}), 1),
|
||||
] {
|
||||
let (mut app, back) = two_files();
|
||||
app.ui.home = true;
|
||||
handle(&mut app, "engine.execute", json!({"document": back, "command": "command.batch", "params": params})).unwrap();
|
||||
assert_eq!(app.session.active, expected);
|
||||
assert_eq!(app.ui.home, expected == 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_batches_discard_their_player_requests_but_keep_older_ui_requests() {
|
||||
// Colliding frame IDs expose a failed batch presenting another file's frame.
|
||||
for named in [false, true] {
|
||||
let (mut app, back) = two_files();
|
||||
let back_frame =
|
||||
handle(&mut app, "engine.execute", json!({"document": back, "command": "frame.create", "params": {}})).unwrap()["id"].clone();
|
||||
let front_frame = handle(&mut app, "engine.execute", json!({"command": "frame.create", "params": {}})).unwrap()["id"].clone();
|
||||
assert_eq!(back_frame, front_frame);
|
||||
app.session.request_ui("panel.assets", json!({}));
|
||||
let result = handle(
|
||||
&mut app,
|
||||
"engine.execute",
|
||||
json!({
|
||||
"document": named.then_some(back), "command": "command.batch", "params": {"commands": [
|
||||
{"command": "proto.present", "params": {"start": back_frame}}, {"command": "does.not.exist"}
|
||||
]}
|
||||
}),
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert_eq!(app.session.active, 1);
|
||||
assert!(app.ui.present.is_none());
|
||||
assert_eq!(app.inspect()["leftTab"], json!("Assets"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_direct_group_rolls_back_ui_requests_and_document_selection() {
|
||||
// A direct grouped call must also roll back effects without an outer command.batch.
|
||||
let (mut app, _) = two_files();
|
||||
let frame = handle(&mut app, "engine.execute", json!({"command": "frame.create", "params": {}})).unwrap()["id"].clone();
|
||||
let revision = app.session.document_selection_revision();
|
||||
app.session.request_ui("panel.assets", json!({}));
|
||||
let result: Result<(), figcraft_engine::EngineError> = app.session.grouped("failed presentation", |session| {
|
||||
session.execute("proto.present", &json!({"start": frame}))?;
|
||||
Err(figcraft_engine::EngineError::Other("abort".into()))
|
||||
});
|
||||
assert!(result.is_err());
|
||||
assert_eq!(app.session.document_selection_revision(), revision);
|
||||
app.handle_ui_requests();
|
||||
assert!(app.ui.present.is_none());
|
||||
assert_eq!(app.inspect()["leftTab"], json!("Assets"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refused_file_commands_keep_their_interactive_dialog_requests() {
|
||||
// A failed standalone command may intentionally request a save or close confirmation.
|
||||
for (command, dialog) in [("file.save", "dialog.saveAs"), ("file.saveAs", "dialog.saveAs"), ("file.close", "dialog.unsaved")] {
|
||||
let (mut app, _) = two_files();
|
||||
app.session.execute("shape.rectangle", &json!({})).unwrap();
|
||||
assert!(app.session.execute(command, &json!({})).is_err());
|
||||
assert!(app.session.ui_requests.iter().any(|request| request.kind == dialog), "{command}");
|
||||
assert_eq!(app.session.docs.len(), 2);
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,22 @@ fn one_interaction(trigger: Value, transition: Value, ms: u32) -> (Harness, Node
|
||||
(u, hot)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrow_key_triggers_override_default_frame_navigation() {
|
||||
// Skipping a frame distinguishes the configured action from default frame navigation.
|
||||
for (name, key) in [("ArrowRight", Key::ArrowRight), ("ArrowLeft", Key::ArrowLeft), ("ArrowUp", Key::ArrowUp), ("ArrowDown", Key::ArrowDown)] {
|
||||
let mut s = Session::new();
|
||||
let a = frame(&mut s, "A", 0.0, 300.0, 400.0);
|
||||
frame(&mut s, "B", 400.0, 300.0, 400.0);
|
||||
let c = frame(&mut s, "C", 800.0, 300.0, 400.0);
|
||||
on(&mut s, a, json!({"type": "keyPress", "key": name}), json!({"type": "navigate", "dest": c}), json!({"type": "instant"}), 0);
|
||||
let mut u = Harness::new(s);
|
||||
u.run("proto.present", json!({"start": a}));
|
||||
u.key(pos2(720.0, 470.0), key);
|
||||
assert_eq!(presenter(&u)["current"], json!(c), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn triggers_fire_on_their_gesture() {
|
||||
let instant = json!({"type": "instant"});
|
||||
|
||||
@@ -592,7 +592,7 @@ pub fn present_owner_active(app: &FigApp) -> bool {
|
||||
}
|
||||
|
||||
/// Puts the presenter on screen back into its tab, where it keeps its state.
|
||||
fn pause_present(app: &mut FigApp) {
|
||||
pub(crate) fn pause_present(app: &mut FigApp) {
|
||||
let Some(p) = app.ui.present.take() else { return };
|
||||
let id = app.ui.present_active;
|
||||
if let Some(t) = app.ui.presents.iter_mut().find(|t| Some(t.id) == id) {
|
||||
|
||||
@@ -79,7 +79,10 @@ unknown id is an error.
|
||||
**Documents.** `engine.execute`, `document.inspect`, `node.get` and `ui.render` take an optional
|
||||
`document`: an open file's `id` (from `doc.list`, or `document.inspect`'s `id`) or its path. The
|
||||
request acts on that file without bringing its tab to the front; the tab in front comes back
|
||||
afterwards unless the command opened or switched to another file itself. A file that isn't open is
|
||||
afterwards unless the command explicitly opens or switches a file (`file.new`, `file.open`,
|
||||
`doc.switch`, `doc.nextTab`, `doc.previousTab`) or shows its prototype (`proto.present`,
|
||||
`proto.preview`). These commands keep the requested file in front even if it was already selected
|
||||
temporarily for this call; a failed command restores the previous tab. A file that isn't open is
|
||||
an error, and so is a `document` naming a file behind the tab in front on any other method
|
||||
(`ui.screenshot`, `ui.input`, `ui.key`… act on what the window shows). `doc.list` includes each file's
|
||||
`path` only when the call names no `agent`: an AI agent's calls (MCP sets `agent`) get ids and names.
|
||||
|
||||
+6
-3
@@ -1527,9 +1527,12 @@ change where the next edit lands. `run_command`, `batch`, `create_node`, `set_pr
|
||||
`inspect_document`, `get_node`, `select`, `export`, `screenshot`, `save_file`, `undo` and `redo`
|
||||
take an optional `document`: the file's `id` (in `run_command {command: "doc.list"}`, and the `id`
|
||||
of the `document` outline `open_file` and `inspect_document` return) or the path of an open file.
|
||||
The call acts on that file and the tab in front stays in front, unless the command itself opens or
|
||||
switches to another file (`file.open`, `file.new`, `doc.switch`), as it would without `document`. A
|
||||
file that isn't open is an error. `doc.list` gives an agent each open file's `id`, name and state, not`nwhere it is on disk (#1117). `screenshot {window}` captures what the window shows, so it
|
||||
The call acts on that file and ordinary reads and edits keep the tab in front. Explicit file/tab
|
||||
commands (`file.open`, `file.new`, `doc.switch`, `doc.nextTab`, `doc.previousTab`) and player commands
|
||||
(`proto.present`, `proto.preview`) keep the requested file in front, including successful commands
|
||||
inside a batch. Failed groups discard their UI requests and explicit selection. A
|
||||
file that isn't open is an error. `doc.list` gives an agent each open file's `id`, name and state, not
|
||||
where it is on disk (#1117). `screenshot {window}` captures what the window shows, so it
|
||||
needs the file in front. Over the control channel, `engine.execute`, `document.inspect`,
|
||||
`node.get` and `ui.render` take the same `document`; other methods refuse one naming a file behind
|
||||
the tab in front. Headless sessions take it too.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Prototyping parity
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-19 · **Change:** patch (without a device, a frame taller than the window with fixed or sticky layers scrolls in the window as on a device's screen, so a fixed header stays at the window's top to the end of the page instead of panning away with the frame (#2430); dragging a prototype connection near the canvas edge pans the view toward it, so a link can reach a frame off screen (#2015); in the presenter's comment mode (C) a click on the presented frame starts a comment there and the mode stays on for the next one, Escape closes the draft and then the mode, measured in Figma's web app 2026-11-10 (#2209); presenting a tall frame is sharp on a HiDPI display: a frame too big for one texture at device scale (a 1440 by 9701 frame at 2 pixels a unit) is still drawn from the capped whole-frame texture, with the part in view drawn again over it from a texture at device scale (#2127); a connection dragged from a variant, or a layer in it, onto a sibling variant makes Change to, On click, Instant, with the sibling outlined (#2158); `proto.settings` refuses an unknown device with the list of devices instead of saving it, takes a known one in any case, and answers the page's settings, so `proto.settings {}` reads them (#2027); Hide UI in the presenter's Options menu, and Cmd/Ctrl+\ as in the editor: the bar above the prototype and the navigation bar under it go away, a toast names the key that brings them back, `proto.presentOptions {hideUi}` (#1820); the Controller menu names each button as PlayStation and Switch controllers do; "Open in new tab" on Open link: off, the web build's own tab goes to the link; a manual overlay's position can be dragged on the canvas (#405); Open link notices now cover mail links, and skipping them covers only links the viewer fired (#1096); overlay positions relative to the layer that opens them; the Triggers row no longer lists delays on mouse triggers as missing; top-level frames bigger than the device's screen scroll in the player; Change to, set variable and set variable mode lay out what they change in the player, as the canvas does; presentation tabs, one per page of a file; a Present tab with device and scale controls (#537); core editor leftovers: delays on mouse triggers and manual overlay offsets; controller buttons on key/gamepad triggers, widgets that react in prototypes, `proto.evaluate` and the mode lookup rules pinned) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-19 · **Change:** patch (platform arrow-key aliases and document-scoped player controls, with failed batch UI requests rolled back; without a device, a frame taller than the window with fixed or sticky layers scrolls in the window as on a device's screen, so a fixed header stays at the window's top to the end of the page instead of panning away with the frame (#2430); dragging a prototype connection near the canvas edge pans the view toward it, so a link can reach a frame off screen (#2015); in the presenter's comment mode (C) a click on the presented frame starts a comment there and the mode stays on for the next one, Escape closes the draft and then the mode, measured in Figma's web app 2026-11-10 (#2209); presenting a tall frame is sharp on a HiDPI display: a frame too big for one texture at device scale (a 1440 by 9701 frame at 2 pixels a unit) is still drawn from the capped whole-frame texture, with the part in view drawn again over it from a texture at device scale (#2127); a connection dragged from a variant, or a layer in it, onto a sibling variant makes Change to, On click, Instant, with the sibling outlined (#2158); `proto.settings` refuses an unknown device with the list of devices instead of saving it, takes a known one in any case, and answers the page's settings, so `proto.settings {}` reads them (#2027); Hide UI in the presenter's Options menu, and Cmd/Ctrl+\ as in the editor: the bar above the prototype and the navigation bar under it go away, a toast names the key that brings them back, `proto.presentOptions {hideUi}` (#1820); the Controller menu names each button as PlayStation and Switch controllers do; "Open in new tab" on Open link: off, the web build's own tab goes to the link; a manual overlay's position can be dragged on the canvas (#405); Open link notices now cover mail links, and skipping them covers only links the viewer fired (#1096); overlay positions relative to the layer that opens them; the Triggers row no longer lists delays on mouse triggers as missing; top-level frames bigger than the device's screen scroll in the player; Change to, set variable and set variable mode lay out what they change in the player, as the canvas does; presentation tabs, one per page of a file; a Present tab with device and scale controls (#537); core editor leftovers: delays on mouse triggers and manual overlay offsets; controller buttons on key/gamepad triggers, widgets that react in prototypes, `proto.evaluate` and the mode lookup rules pinned) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
**Breadth ~92%, ready ~74% (estimated).** Every Figma trigger except media, every action except
|
||||
media control, every transition and easing exist; key/gamepad triggers take controller buttons,
|
||||
read from controllers on Windows and in the browser. Every rule of the public
|
||||
documentation on triggers, actions, overlays, animations, easing, scrolling and interactive
|
||||
components is a test case with what it implies (`crates/engine/src/proto_behaviour_tests.rs`, 7
|
||||
tests on the model, and `crates/ui-egui/src/present/behaviour_tests.rs`, 14 tests driving the
|
||||
tests on the model, and `crates/ui-egui/src/present/behaviour_tests.rs`, 15 tests driving the
|
||||
player, 21 gestures among them; presentation tabs: `crates/ui-egui/src/present_tab_tests.rs`, 6
|
||||
tests; the tail: `crates/engine/src/proto_tail_tests.rs`, 4 tests, and
|
||||
`crates/ui-egui/src/present/tail_tests.rs`, 5 tests), and all pass. Not yet checked against
|
||||
@@ -15,7 +15,7 @@ larger real prototypes. Remaining: 2–5 h.
|
||||
|
||||
| Group | Figma | FigCraft | Missing |
|
||||
|---|---|---|---|
|
||||
| Triggers | On click, on drag, while hovering, while pressing, key/gamepad, mouse enter, mouse leave, mouse down, mouse up, after delay, on media hit, on media end | 10: OnClick, OnHover, OnPress, OnDrag, MouseEnter, MouseLeave, MouseDown, MouseUp, AfterDelay, KeyPress (keys, combinations and controller buttons) | media triggers; controllers on macOS, Linux and FreeBSD |
|
||||
| Triggers | On click, on drag, while hovering, while pressing, key/gamepad, mouse enter, mouse leave, mouse down, mouse up, after delay, on media hit, on media end | 10: OnClick, OnHover, OnPress, OnDrag, MouseEnter, MouseLeave, MouseDown, MouseUp, AfterDelay, KeyPress (keys, combinations, platform arrow aliases and controller buttons) | media triggers; controllers on macOS, Linux and FreeBSD |
|
||||
| Actions | Navigate to, change to, back, scroll to, open link, open / swap / close overlay, set variable, set variable mode, conditional, play/pause/mute/seek media | 11: Navigate, Back, ScrollTo (with an offset), OpenOverlay, SwapOverlay, CloseOverlay, OpenUrl, ChangeTo, SetVariable, SetVariableMode, Conditional | media actions |
|
||||
| Transitions | Instant, dissolve, smart animate, move in/out, push, slide in/out | all 8 | — |
|
||||
| Easing | Linear, ease in/out/in-and-out, back variants, gentle, quick, bouncy, slow, custom bezier, custom spring | all 13 (springs physical) | — |
|
||||
@@ -108,6 +108,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-15 | patch | M5: `ArrowRight` and the platform name `Right` match the same trigger without bypassing modifiers. Explicit file/tab/player commands keep the requested document; nested batches use only successful selections, and aborted groups discard their UI requests. Ordinary background reads and edits keep the front tab. Tests: `control::document_tests`, `headless::document_tests`, `arrow_key_triggers_override_default_frame_navigation`; estimates unchanged. |
|
||||
| 2026-11-07 | patch | M8, #2015: dragging a prototype connection near the canvas edge pans the view, as measured in Figma: while a drag holds the pointer within about 15 px of the edge (or past it) the view pans toward it at 40 px/s for each px closer, up to 600 px/s at the edge, steadily while the pointer stays still; moving layers, the selection box, drawing a shape and dragging a prototype connection (a link can now reach a frame off screen). Resizing, rotating and other drags don't pan. Tests: `view_autopan_tests`, `canvas_autopan_tests`, `proto_canvas::tests`. |
|
||||
| 2026-11-14 | patch | M5, #2352: a chain of variant changes on After delay plays to the end (A to B to C to D); before, the step a variant had fired stayed marked as fired when the instance changed variant, so the chain stopped after one step, and now each step's delay counts from when its variant appears (`crates/ui-egui/src/present/afterdelay_chain_tests.rs`). Numbers unchanged |
|
||||
| 2026-11-09 | patch | M7, #2158: a connection dragged from a variant (or a layer in it) onto a sibling variant of its set did nothing, because the drop looked only for top-level frames and a variant's top-level frame is its set. It now creates Change to the sibling (On click, Instant, as measured in Figma's web app) and outlines the sibling while dragging; the set's background and the variant itself still add nothing, and a frame outside the set still gets Navigate to |
|
||||
|
||||
Reference in new issue
Block a user