From e7dfc815d16555d6c4bdbe775466a81927a1092b Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Tue, 10 Nov 2026 06:49:59 -0500 Subject: [PATCH] M7: Present mode: a click in comment mode adds a comment on the frame (#2209) In the presenter's comment mode a click on the presented frame starts a draft at the clicked point (mapped back through the presenter's placement) and opens the editor's composer beside a pin; posting adds the comment on the frame's page and the mode stays on. Escape closes the draft, then the mode. While the mode is on the player ignores the pointer, so no click interaction or hotspot fires. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/canvas/comments.rs | 84 +++++++++++++++++++-------- crates/ui-egui/src/comments_tests.rs | 82 ++++++++++++++++++++++++++ crates/ui-egui/src/present/chrome.rs | 14 ++++- crates/ui-egui/src/present/player.rs | 7 ++- docs/prototyping-parity.md | 5 +- 5 files changed, 163 insertions(+), 29 deletions(-) diff --git a/crates/ui-egui/src/canvas/comments.rs b/crates/ui-egui/src/canvas/comments.rs index a9e9c1267..b7410f9c6 100644 --- a/crates/ui-egui/src/canvas/comments.rs +++ b/crates/ui-egui/src/canvas/comments.rs @@ -830,37 +830,46 @@ fn escape(app: &mut FigApp, ctx: &egui::Context) -> bool { true } +/// The draft's composer next to its pin at `at` (screen), kept inside `bounds`; posting adds the +/// comment (on `page` when given, else the current one) and shows its thread. The editor and the +/// presenter both draw it here. +fn draft_composer(app: &mut FigApp, ctx: &egui::Context, at: Pos2, bounds: Rect, page: Option) { + let Some((x, y, mut text)) = app.ui.comments.draft.clone() else { return }; + let t = Tokens::get(ctx); + let people = app.session.doc().map(|d| d.comment_people()).unwrap_or_default(); + let me = me(app); + let mut pick = std::mem::take(&mut app.ui.comments.mention); + let mut post = false; + egui::Area::new(Id::unique("comment_draft")).order(egui::Order::Foreground).fixed_pos(popover_pos(at, bounds)).show(ctx, |ui| { + popover_frame(&t).show(ui, |ui| { + ui.set_width(POPOVER_W - 24.0); + post = composer(ui, Id::unique("comment_draft_text"), &mut text, tr("Add a comment"), &people, &me, &mut pick); + }); + }); + app.ui.comments.mention = pick; + if post { + let mut params = json!({"x": x, "y": y, "text": text.trim(), "anchor": true}); + if let (Some(page), Some(o)) = (page, params.as_object_mut()) { + o.insert("page".into(), json!(page)); + } + let r = app.run("comment.add", params); + app.ui.comments.draft = None; + if let Some(id) = r.and_then(|v| v.get("id").and_then(Value::as_u64)) { + app.ui.comments.show(id); + } + } else if let Some(d) = &mut app.ui.comments.draft { + d.2 = text; + } +} + /// The thread popover and the draft composer, floating next to their pins on the canvas. pub fn popovers(app: &mut FigApp, ctx: &egui::Context) { if escape(app, ctx) { return; } let canvas = app.canvas.rect; - if let Some((x, y, mut text)) = app.ui.comments.draft.clone() { - let t = Tokens::get(ctx); - let people = app.session.doc().map(|d| d.comment_people()).unwrap_or_default(); - let me = me(app); - let mut pick = std::mem::take(&mut app.ui.comments.mention); - let mut post = false; - egui::Area::new(Id::unique("comment_draft")).order(egui::Order::Foreground).fixed_pos(popover_pos(app.to_screen(x, y), canvas)).show( - ctx, - |ui| { - popover_frame(&t).show(ui, |ui| { - ui.set_width(POPOVER_W - 24.0); - post = composer(ui, Id::unique("comment_draft_text"), &mut text, tr("Add a comment"), &people, &me, &mut pick); - }); - }, - ); - app.ui.comments.mention = pick; - if post { - let r = app.run("comment.add", json!({"x": x, "y": y, "text": text.trim(), "anchor": true})); - app.ui.comments.draft = None; - if let Some(id) = r.and_then(|v| v.get("id").and_then(Value::as_u64)) { - app.ui.comments.show(id); - } - } else if let Some(d) = &mut app.ui.comments.draft { - d.2 = text; - } + if let Some((x, y, _)) = app.ui.comments.draft { + draft_composer(app, ctx, app.to_screen(x, y), canvas, None); return; } let Some(open) = app.ui.comments.open else { return }; @@ -1228,6 +1237,31 @@ pub fn presenter(app: &mut FigApp, ctx: &egui::Context, frame: NodeId, place: cr if let Some(id) = clicked { toggle(app, id); } + // A click on the presented frame (not on a pin or a popover) starts a comment there: the + // presented point back to the frame as designed. + let frame_rect = place.rect(fb).intersect(clip); + let click = ctx.input(|i| if i.pointer.primary_clicked() { i.pointer.interact_pos() } else { None }); + if clicked.is_none() + && let Some(q) = click.filter(|q| frame_rect.contains(*q)) + && ctx.layer_id_at(q).is_none_or(|l| l.order == egui::Order::Background) + { + let pt = place.page(q); + start_draft(app, fb.x0 + (pt.x - place.page_min.0), fb.y0 + (pt.y - place.page_min.1)); + } + if let Some((x, y, _)) = app.ui.comments.draft { + let at = to_screen((x, y)); + let r = pin_rect(at); + egui::Area::new(Id::unique("present_comment_draft_pin")).order(egui::Order::Foreground).fixed_pos(r.min).interactable(false).show( + ctx, + |ui| { + let (rr, _) = ui.allocate_exact_size(r.size(), Sense::hover()); + ui.painter().rect_filled(rr, BUBBLE, ACCENT); + ui.painter().circle_filled(rr.center(), 3.0, crate::theme::ACCENT_ON); + }, + ); + draft_composer(app, ctx, at, ctx.content_rect(), doc.page_of(frame)); + return; + } match app.ui.comments.open.and_then(|o| pins.iter().find(|p| p.id == o)) { Some(p) => thread(app, ctx, p.id, p.at, ctx.content_rect()), // A thread on another frame (or none) closes. diff --git a/crates/ui-egui/src/comments_tests.rs b/crates/ui-egui/src/comments_tests.rs index 0ccd32f10..f97f4f0a4 100644 --- a/crates/ui-egui/src/comments_tests.rs +++ b/crates/ui-egui/src/comments_tests.rs @@ -272,6 +272,88 @@ fn the_presenter_shows_the_frames_comments() { let _ = other; } +/// A presenter on a 400 x 300 frame (at page 50, 40) with a second frame, the comment mode on. +/// Returns the harness, the frame, the other frame and the presented frame's top-left on screen. +fn present_comment_mode() -> (Ui, figcraft_doc::NodeId, figcraft_doc::NodeId, Pos2) { + let mut s = Session::new(); + let f = id(&s.execute("node.create", &json!({"type": "frame", "x": 50, "y": 40, "width": 400, "height": 300})).unwrap()); + let other = id(&s.execute("node.create", &json!({"type": "frame", "x": 700, "y": 0, "width": 400, "height": 300})).unwrap()); + let mut u = Ui::new(s); + u.run("proto.present", json!({"start": f})); + key(&mut u, Key::C, Modifiers::NONE); + assert_eq!(u.app.inspect()["presenter"]["comments"], true); + let screen = egui::Rect::from_min_size(pos2(0.0, 80.0), vec2(1440.0, 820.0)); + (u, f, other, screen.center() - vec2(200.0, 150.0)) +} + +fn comment_count(u: &Ui) -> usize { + u.app.session.doc().unwrap().comments.len() +} + +#[test] +fn a_click_in_the_presenters_comment_mode_adds_a_comment_on_the_frame() { + let (mut u, f, _, frame_min) = present_comment_mode(); + click(&mut u, frame_min + vec2(120.0, 90.0)); + assert!(comments(&u)["draft"].is_array(), "the click opens a draft"); + u.frame(vec![Event::Text("hello".into())]); + key(&mut u, Key::Enter, Modifiers::NONE); + assert_eq!(comment_count(&u), 1); + let doc = u.app.session.doc().unwrap(); + let c = &doc.comments[0]; + assert_eq!(c.first.text, "hello"); + assert_eq!(c.anchor, Some(f)); + assert!((c.x - 120.0).abs() <= 1.0 && (c.y - 90.0).abs() <= 1.0, "frame-relative spot {},{}", c.x, c.y); + assert_eq!(u.app.inspect()["presenter"]["comments"], true, "the mode stays on"); + assert!(u.app.ui.present.is_some()); +} + +#[test] +fn a_click_off_the_frame_in_the_presenters_comment_mode_adds_no_draft() { + let (mut u, _, _, frame_min) = present_comment_mode(); + click(&mut u, frame_min + vec2(-60.0, 90.0)); + assert!(comments(&u)["draft"].is_null()); + assert_eq!(comment_count(&u), 0); + assert_eq!(u.app.inspect()["presenter"]["comments"], true); +} + +#[test] +fn escape_closes_the_presenters_draft_then_the_mode() { + let (mut u, _, _, frame_min) = present_comment_mode(); + click(&mut u, frame_min + vec2(120.0, 90.0)); + u.frame(vec![Event::Text("draft".into())]); + key(&mut u, Key::Escape, Modifiers::NONE); + assert!(comments(&u)["draft"].is_null(), "Escape closes the draft"); + assert_eq!(comment_count(&u), 0, "and adds no comment"); + assert_eq!(u.app.inspect()["presenter"]["comments"], true); + assert!(u.app.ui.present.is_some()); + key(&mut u, Key::Escape, Modifiers::NONE); + assert_eq!(u.app.inspect()["presenter"]["comments"], false, "Escape with no draft turns the mode off"); + assert!(u.app.ui.present.is_some(), "and keeps the presentation open"); + key(&mut u, Key::Escape, Modifiers::NONE); + assert!(u.app.ui.present.is_none(), "with the mode off Escape still ends the presentation"); +} + +#[test] +fn a_click_in_the_presenters_comment_mode_does_not_navigate() { + let (mut u, f, other, frame_min) = present_comment_mode(); + u.run("proto.interaction.add", json!({"id": f, "trigger": {"type": "onClick"}, "action": {"type": "navigate", "dest": other}})); + u.frames(2, Vec::new); + click(&mut u, frame_min + vec2(120.0, 90.0)); + u.frames(30, Vec::new); + assert_eq!(u.app.inspect()["presenter"]["current"], json!(f), "the click placed a comment, it didn't follow the link"); + assert!(comments(&u)["draft"].is_array()); +} + +#[test] +fn typing_c_into_the_presenters_draft_keeps_the_mode_on() { + let (mut u, _, _, frame_min) = present_comment_mode(); + click(&mut u, frame_min + vec2(120.0, 90.0)); + u.frame(vec![Event::Text("c".into())]); + key(&mut u, Key::C, Modifiers::NONE); + assert_eq!(u.app.inspect()["presenter"]["comments"], true); + assert!(comments(&u)["draft"].is_array()); +} + #[derive(Clone, Default)] struct Clip(Arc>>); diff --git a/crates/ui-egui/src/present/chrome.rs b/crates/ui-egui/src/present/chrome.rs index 4fc57ff0f..d29fd40e2 100644 --- a/crates/ui-egui/src/present/chrome.rs +++ b/crates/ui-egui/src/present/chrome.rs @@ -94,12 +94,24 @@ pub fn show(app: &mut FigApp, ui: &mut Ui) { } _ => {} } + // Escape with no draft or thread open turns the comment mode off and keeps the presentation. + let cu = &app.ui.comments; + if live + && pres.view.comments + && pres.link_notice.is_none() + && cu.open.is_none() + && cu.draft.is_none() + && !cu.mention.active() + && ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) + { + pres.view.comments = false; + } if live && pres.view.comments && let Some((frame, place, clip)) = pres.shown { crate::comments::presenter(app, &ctx, frame, place, clip); - } else if app.ui.comments.open.is_some() { + } else if app.ui.comments.open.is_some() || app.ui.comments.draft.is_some() { app.ui.comments.close(); } finish(app, &mut pres); diff --git a/crates/ui-egui/src/present/player.rs b/crates/ui-egui/src/present/player.rs index 8bcbea09d..ff821620a 100644 --- a/crates/ui-egui/src/present/player.rs +++ b/crates/ui-egui/src/present/player.rs @@ -60,7 +60,12 @@ pub(super) fn player(p: &mut Presenter, ui: &mut Ui, rect: Rect, now: f64, chrom // The pane only takes the keyboard while the pointer is over it. While a link notice shows // the prototype takes neither keys nor the pointer (Escape there cancels the notice). let keys = chrome.keys && p.link_notice.is_none() && (!chrome.pane || over); - input(p, &ctx, &l, InputMode { over_area: over && p.link_notice.is_none(), keys_on: keys, pane: chrome.pane, now }); + input( + p, + &ctx, + &l, + InputMode { over_area: over && p.link_notice.is_none() && !(p.view.comments && !chrome.pane), keys_on: keys, pane: chrome.pane, now }, + ); } else { p.pads.clear(); } diff --git a/docs/prototyping-parity.md b/docs/prototyping-parity.md index 7c216bcae..50ebc706c 100644 --- a/docs/prototyping-parity.md +++ b/docs/prototyping-parity.md @@ -1,6 +1,6 @@ # Prototyping parity -> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-06 · **Change:** patch (`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-10 · **Change:** patch (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); `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, @@ -92,7 +92,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr | Interactive components: instances play their variant's interactions, overridden per trigger | done | | | Drag-driven animations that follow the pointer, in their direction | done | | | Presenter: device frames and colours, rotation, custom sizes, fit/fill/100%, responsive frames | done | device bodies drawn in code. Presenting opens a tab for the page, named "file - page", which keeps its screen and history while you go back to the design, with a thumbnail of the current frame, previous / next, device presets and scale choices; the frame is laid out again for the device's screen on the prototype's copy (constraints and auto layout; the file is untouched); on phones and tablets overflowing content drags while the device stays put: a top-level frame bigger than the screen always scrolls (as in Figma, with no overflow setting), content past the frame's own edges as its overflow setting allows ("No scrolling" clips it); closing the window asks about unsaved changes above the presentation (#537). Devices not compared with Figma's | -| Hotspot hints, inspect panel in the presenter, comments in the presenter | done | | +| Hotspot hints, inspect panel in the presenter, comments in the presenter | done | in comment mode (C) a click on the presented frame starts a comment there (a click off the frame does nothing, and the prototype's own click interactions don't fire) and the mode stays on for the next comment; Escape closes the draft, then the mode (the presentation stays open), as measured in Figma's web app 2026-11-10 (#2209). No comments sidebar in the presenter | | Hide UI in the presenter (Options menu, Cmd/Ctrl+\) | done | the bar above the prototype and the navigation bar under it go away and the prototype takes their room; a toast names the key that brings them back; `proto.presentOptions {hideUi}`, kept for later presentations (#1820) | | Preview pane following edits live | done | | | Edit interactions on several layers at once | done | | @@ -107,6 +107,7 @@ tool; opt-in), **silent** (the documentation doesn't say; the case pins the curr | Date | Change | Summary | |---|---|---| +| 2026-11-10 | patch | M7, #2209: the presenter's comment mode showed the frame's pins but nothing started a comment. Measured in Figma's web app: with the mode on (C or the bar's comment button) a click on the presented frame drops a pin at the click and opens an "Add a comment" composer beside it; Enter posts, the pin stays at the same frame-relative spot and the mode stays on; a click on the background does nothing; Escape closes a composer, and with none open turns the mode off; the comment shows on the frame in the editor. Now the same: the click starts the draft at the point mapped back through the presenter's placement, the editor's composer is shared, the post carries the frame's page, the player ignores the pointer while the mode is on (no click interactions or hotspots fire), and Escape closes the draft, then the mode. Tests: `comments_tests::a_click_in_the_presenters_comment_mode_adds_a_comment_on_the_frame` and four more. | | 2026-11-06 | patch | M5, #2027: `proto.settings` took any string as the device (`"Pixel Nonexistent"`, `"iphone 16"`) and saved it in the file; the presenter then drew no device while its picker showed the name as if it were one, and the settings couldn't be read back over MCP (`proto.settings {}` answered `{ok: true}`). An unknown name (or a non-string) is now refused with every name the picker offers (`None`, `Custom size` and the devices), as an unknown colour is refused with the device's colours, and nothing changes; a known name is taken in any case and stored as the picker spells it. Every call answers the page's settings after it: device, background, rotation, the colour shown, the screen as presented, the custom size and responsive. Test: `proto_present_tests::unknown_devices_are_refused_and_settings_read_back` | | 2026-10-31 | minor | Gap 15: the Controller menu names buttons as PlayStation and Switch controllers do; that item leaves the missing list. Estimate unchanged. Test: `present::tail_tests`. | | 2026-10-30 | minor | Opening a link in place: Open link has "Open in new tab", on by default; off, the web build's own tab goes to the link after the notice (or at once with it skipped); the desktop app has no tab of its own and opens the browser either way. Saved in files only when off (`openInNewTab`) and read from REST files. |