From 28233d8c247b27c76dd0a00d42e894eddfb6ab70 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:40:59 +0100 Subject: [PATCH 1/2] fix(ui): commit plugin fields before button callbacks --- crates/ui-egui/src/dialogs/plugins_ui.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs/plugins_ui.rs b/crates/ui-egui/src/dialogs/plugins_ui.rs index d335b277a..5348febd2 100644 --- a/crates/ui-egui/src/dialogs/plugins_ui.rs +++ b/crates/ui-egui/src/dialogs/plugins_ui.rs @@ -606,9 +606,10 @@ fn form_window(app: &mut FigApp, ctx: &Context) { /// Parameters or panel controls in two columns (label, field); buttons in a row share one line, /// the first button filled. Returns what the user did to which control. fn controls(ui: &mut Ui, salt: &str, params: &[Param], values: &Map, t: &Tokens) -> Vec { - // In order: a tap's press and release share a frame, so a field that loses the keyboard - // commits in the same frame as the button that took it. + // A tap can commit a field and press a button in one frame. Apply the field change before + // delivering the button event, regardless of the controls' visual order. let mut used = Vec::new(); + let mut button_hits = Vec::new(); let mut first_button = true; egui::Grid::new(("plugin_controls", salt)).num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| { for row in params.chunk_by(|a, b| a.kind == ParamKind::Button && b.kind == ParamKind::Button) { @@ -635,11 +636,14 @@ fn controls(ui: &mut Ui, salt: &str, params: &[Param], values: &Map { - ui.horizontal(|ui| { - let pressed = row.iter().filter(|b| widgets::button(ui, b.title(), std::mem::take(&mut first_button), true).clicked()); - pressed.last().map(|b| Used::Set(b.name.clone(), Value::Null)) - }) - .inner + let button = ui + .horizontal(|ui| { + let pressed = row.iter().filter(|b| widgets::button(ui, b.title(), std::mem::take(&mut first_button), true).clicked()); + pressed.last().map(|b| Used::Set(b.name.clone(), Value::Null)) + }) + .inner; + button_hits.extend(button); + None } _ => { let current = values.get(&p.name).cloned().unwrap_or_else(|| p.default_value()); @@ -650,6 +654,7 @@ fn controls(ui: &mut Ui, salt: &str, params: &[Param], values: &Map Date: Sat, 21 Nov 2026 17:42:04 +0100 Subject: [PATCH 2/2] Check that the plugin button sees the edited field value --- crates/ui-egui/src/plugin_panel_tests.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/plugin_panel_tests.rs b/crates/ui-egui/src/plugin_panel_tests.rs index bee4e45cc..4ceb182bc 100644 --- a/crates/ui-egui/src/plugin_panel_tests.rs +++ b/crates/ui-egui/src/plugin_panel_tests.rs @@ -34,12 +34,17 @@ pub(crate) fn panel_module() -> Vec { r#"(module (import "figcraft" "call" (func $call (param i32 i32 i32 i32) (result i32))) (import "figcraft" "ui_show" (func $ui_show (param i32 i32) (result i32))) + (import "figcraft" "reply_read" (func $reply_read (param i32 i32) (result i32))) + (import "figcraft" "set_output" (func $set_output (param i32 i32))) (memory (export "memory") 1) (data (i32.const 1000) "{}") (data (i32.const 100) "shape.rectangle") (data (i32.const 200) "{}") + (data (i32.const 49152) "event ") (func (export "figcraft_run") (param $n i32) (result i32) (i32.store (i32.const 0) (i32.add (i32.load (i32.const 0)) (i32.const 1))) (if (i32.eq (i32.load (i32.const 0)) (i32.const 1)) (then (return (call $ui_show (i32.const 1000) (i32.const {}))))) + (drop (call $reply_read (i32.const 49158) (local.get $n))) + (call $set_output (i32.const 49152) (i32.add (i32.const 6) (local.get $n))) (call $call (i32.const 100) (i32.const 15) (i32.const 200) (i32.const {}))))"#, spec.replace('"', "\\\""), rect.replace('"', "\\\""), @@ -188,7 +193,12 @@ fn a_slider_calls_the_plugin_back_once_when_let_go() { /// keyboard from commits in the frame the button is clicked, and the plugin gets both, in order. #[test] fn a_tap_on_a_button_keeps_what_was_typed_in_a_field() { - let mut u = Ui::new(session()); + let mut session = session(); + let open = &mut session.plugins.panels[0]; + open.panel.controls.retain(|p| matches!(p.name.as_str(), "size" | "go")); + open.panel.controls.swap(0, 1); + open.values.retain(|name, _| name == "size"); + let mut u = Ui::new(session); u.ctx.enable_accesskit(); u.frame(vec![]); let at = |u: &mut Ui, label: &str| { @@ -208,4 +218,8 @@ fn a_tap_on_a_button_keeps_what_was_typed_in_a_field() { u.frame(vec![]); assert_eq!(u.app.session.plugins.panel("org.test.panel").unwrap().values["size"], 33.0, "the field's value arrived"); assert_eq!(layers(&u), before + 2, "the field's commit and the button each called the plugin"); + let (message, _) = u.app.ui.toast.as_ref().expect("plugin callback output"); + let event: Value = serde_json::from_str(message.strip_prefix("event ").expect("recorded event")).unwrap(); + assert_eq!(event["event"]["control"], "go"); + assert_eq!(event["values"]["size"], 33.0); }