Merge #322: fix(vector): keep the canvas still when entering vector edit mode and picking a region (@rcoenen)

This commit is contained in:
bflatastic
2026-10-15 19:55:04 +07:00
3 changed files with 31 additions and 11 deletions
+2
View File
@@ -165,6 +165,8 @@ mod variables_export_ui_tests;
#[cfg(test)]
mod variables_rename_tests;
#[cfg(test)]
mod vector_panel_tests;
#[cfg(test)]
mod vector_tail_ui_tests;
#[cfg(test)]
mod web_clipboard_tests;
+3 -11
View File
@@ -12,7 +12,7 @@ use crate::FigApp;
use crate::i18n::tr;
use crate::icons::Icon;
use crate::right::{CAP_ART_W, cap_art, join_label, menu_item, menu_item_with, menu_popup, row};
use crate::widgets::{self, FieldEdit, Lead, PAD};
use crate::widgets::{self, FieldEdit, Lead};
/// Run a point command from a field: typed values are one step, scrubs one step when released.
fn point_field(app: &mut FigApp, cmd: &str, edit: Option<FieldEdit>, params: impl Fn(f64) -> Value) {
@@ -38,11 +38,7 @@ fn width_point(app: &mut FigApp, ui: &mut Ui, doc: &Document, ve: &VectorEdit) {
let sel = ve.width_point.and_then(|i| Some((i, *stroke?.profile()?.points.get(i)?)));
let Some((i, p)) = sel else {
let t = crate::theme::Tokens::get(ui.ctx());
ui.horizontal(|ui| {
ui.add_space(PAD);
widgets::label(ui, tr("Drag the stroke to add a width point"), t.text_secondary);
});
ui.add_space(8.0);
widgets::note(ui, tr("Drag the stroke to add a width point"), t.text_secondary);
return;
};
let weight = stroke.map_or(1.0, |s| s.weight);
@@ -85,11 +81,7 @@ pub fn points(app: &mut FigApp, ui: &mut Ui, doc: &Document, ve: &VectorEdit) {
widgets::section_header(ui, if pts.len() > 1 { tr("Points") } else { tr("Point") }, &[], false);
if pts.is_empty() {
let t = crate::theme::Tokens::get(ui.ctx());
ui.horizontal(|ui| {
ui.add_space(PAD);
widgets::label(ui, tr("Select points to edit their position, radius and mirroring"), t.text_secondary);
});
ui.add_space(8.0);
widgets::note(ui, tr("Select points to edit their position, radius and mirroring"), t.text_secondary);
return;
}
let col = widgets::col_width(ui.available_width());
+26
View File
@@ -0,0 +1,26 @@
//! The Design panel in vector edit mode keeps its width, so the canvas doesn't move under the
//! pointer when the panel's contents change.
use serde_json::json;
#[test]
fn the_canvas_stays_put_entering_vector_edit_mode_and_picking_a_region() {
let (mut h, _) = crate::live_tests::Harness::new();
h.app.session.execute("file.newFromTemplate", &json!({"template": "mobile-app"})).unwrap();
// A wide vector with a filled area: the panel shows its long hint until something is picked.
let id = {
let doc = h.app.session.doc().unwrap();
doc.nodes().filter(|n| n.name == "Near ridge").max_by(|a, b| a.height.total_cmp(&b.height)).map(|n| n.id).unwrap()
};
let canvas = |h: &mut crate::live_tests::Harness| {
h.frames(4);
h.app.inspect()["canvas"]["rect"].clone()
};
h.app.session.execute("select.set", &json!({"ids": [id.0]})).unwrap();
let before = canvas(&mut h);
h.app.session.execute("vector.edit.begin", &json!({})).unwrap();
assert_eq!(canvas(&mut h), before, "the hint for an empty point selection wraps instead of widening the panel");
h.app.session.execute("vector.edit.select", &json!({"regions": [0]})).unwrap();
assert_eq!(canvas(&mut h), before, "picking a region doesn't move the canvas either");
h.app.session.execute("vector.edit.tool", &json!({"tool": "width"})).unwrap();
assert_eq!(canvas(&mut h), before, "nor does the width tool's hint");
}