diff --git a/crates/ui-egui/src/component_set_narrow_tests.rs b/crates/ui-egui/src/component_set_narrow_tests.rs index 1d163c4e8..0024a3640 100644 --- a/crates/ui-egui/src/component_set_narrow_tests.rs +++ b/crates/ui-egui/src/component_set_narrow_tests.rs @@ -110,6 +110,16 @@ fn the_edit_property_window_renames_a_value_and_adds_one() { click(&mut u, centre(&edit)); u.frame(vec![]); assert!(u.app.ui.prop_edit.is_some()); + // Another tab in front closes it (the window also checks the document, not only the ids). + u.app.run("file.new", json!({})); + u.frame(vec![]); + assert!(u.app.ui.prop_edit.is_none(), "another document closes the window"); + u.app.run("doc.switch", json!({"index": 0})); + u.frame(vec![]); + let edit = tree(&mut u).into_iter().find(|n| label(n) == "Edit property" && n.bounds().is_some()).expect("an edit button"); + click(&mut u, centre(&edit)); + u.frame(vec![]); + assert!(u.app.ui.prop_edit.is_some()); // Another selection closes it. u.app.run("select.set", json!({"ids": [variants[0]]})); u.frame(vec![]); diff --git a/crates/ui-egui/src/panels/component_panel.rs b/crates/ui-egui/src/panels/component_panel.rs index 69e1dc16e..ccfc661e9 100644 --- a/crates/ui-egui/src/panels/component_panel.rs +++ b/crates/ui-egui/src/panels/component_panel.rs @@ -218,8 +218,9 @@ const INDENT: f32 = 22.0; const BUTTON: f32 = 22.0; /// A variant property's name field at most (its buttons take the rest of the row). const NAME_W: f32 = 150.0; -/// The Edit property window. +/// The Edit property window, and the most its list of values takes before it scrolls. const EDIT_W: f32 = 240.0; +const VALUES_H: f32 = 320.0; /// A shared property's default (a text field, a dropdown; a checkbox takes less). const SHARED_W: f32 = 84.0; @@ -326,7 +327,8 @@ fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId) { } let edit = icons::button(ui, Icon::Adjust, BUTTON, editing, tr("Edit property")); if edit.clicked() { - app.ui.prop_edit = (!editing).then(|| PropEdit::new(owner, k, edit.rect)); + let doc = app.session.ds().map_or(0, |d| d.uid); + app.ui.prop_edit = (!editing).then(|| PropEdit::new(doc, owner, k, edit.rect)); } else if editing && let Some(e) = app.ui.prop_edit.as_mut() { // The window closes on a press outside it, except on the button that toggles it. e.button = edit.rect; @@ -437,6 +439,8 @@ fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId) { /// The Edit property window of one variant property (#2345): its default and its values, opened /// from the property's row beside the Design panel. pub struct PropEdit { + /// The document it edits: another tab in front closes it. + doc: u64, pub owner: NodeId, pub name: String, /// The row's button that opened it: the window opens level with it, and a press on it toggles @@ -446,9 +450,9 @@ pub struct PropEdit { } impl PropEdit { - fn new(owner: NodeId, name: &str, button: egui::Rect) -> Self { + fn new(doc: u64, owner: NodeId, name: &str, button: egui::Rect) -> Self { let pop = crate::popover::Popover::new(("prop_edit", owner), tr("Edit property")).width(EDIT_W); - PropEdit { owner, name: name.to_string(), button, pop } + PropEdit { doc, owner, name: name.to_string(), button, pop } } } @@ -474,8 +478,8 @@ enum PropAct { /// its set is no longer the selection or the property is gone. pub fn prop_edit_window(app: &mut FigApp, ctx: &egui::Context) { let Some(mut e) = app.ui.prop_edit.take() else { return }; - let Ok(doc) = app.session.ds().map(|d| d.doc.clone()) else { return }; - if app.session.selection() != [e.owner] { + let Ok((uid, doc)) = app.session.ds().map(|d| (d.uid, d.doc.clone())) else { return }; + if uid != e.doc || app.session.selection() != [e.owner] { return; } let Some(vals) = variant_options(&doc, e.owner).into_iter().find(|(k, _)| *k == e.name).map(|(_, v)| v) else { return }; @@ -514,13 +518,16 @@ pub fn prop_edit_window(app: &mut FigApp, ctx: &egui::Context) { }); ui.add_space(4.0); widgets::label(ui, tr("Values"), t.text_secondary); - for v in &vals { - if let Some(nv) = widgets::text_field(ui, Id::unique(("prop_edit_value", owner, name.as_str(), v.as_str())), v, w, tr("Value")) - && nv != *v - { - act = Some(PropAct::RenameValue(v.clone(), nv)); + // Many values scroll, so the button under them stays on the screen. + egui::ScrollArea::vertical().max_height(VALUES_H).auto_shrink([false, true]).show(ui, |ui| { + for v in &vals { + if let Some(nv) = widgets::text_field(ui, Id::unique(("prop_edit_value", owner, name.as_str(), v.as_str())), v, w, tr("Value")) + && nv != *v + { + act = Some(PropAct::RenameValue(v.clone(), nv)); + } } - } + }); ui.add_space(4.0); if widgets::button(ui, tr("Add variant with a new value"), false, true).clicked() { act = Some(PropAct::AddValue);