Keep diagram selection after dragging and record native port evidence

This commit is contained in:
2026-09-05 18:26:19 +03:00
parent c7101b970a
commit 2ef16dc7d2
6 changed files with 103 additions and 6 deletions
+18 -3
View File
@@ -653,7 +653,15 @@ impl App {
}
Message::SelectProject => self.select(self.project().id),
Message::SelectNode(id) => {
if self.selected_node == Some(id) || self.selected == id {
if (self.selected_node == Some(id)
&& self.active_diagram
.and_then(|diagram| self.project().diagrams.get(&diagram))
.and_then(|diagram| diagram.nodes.get(&id))
.is_some_and(|node| self.selected == node.element))
// Defer a placement draft until release: it may change the
// identity captured by the just-started canvas gesture.
|| (self.selected == id && self.draft.as_ref().is_some_and(Draft::dirty))
{
return Task::none();
}
let original = self.selected;
@@ -1107,12 +1115,19 @@ impl App {
} else {
node
};
self.execute(Command::MoveNode {
if self.execute(Command::MoveNode {
diagram,
node,
position,
with_descendants: true,
});
}) && let Some(placement) =
self.project().diagrams[&diagram].nodes.get(&node)
{
// A drag edits a placement, but the canvas still selects
// the engineering element represented by that placement.
self.selected = placement.element;
self.refresh_draft();
}
}
}
Message::Zoom(factor) => {
+56
View File
@@ -564,6 +564,62 @@ fn selecting_current_constructors_preserves_payloads() {
send(&mut app, Message::Apply);
assert_eq!(*app.project(), accepted);
}
#[test]
fn dragging_keeps_semantic_selection_and_same_node_remains_editable() {
let mut app = App::with_project(fixture());
let diagram = app.active_diagram.unwrap();
let placement = app.project().diagrams[&diagram]
.nodes
.values()
.next()
.unwrap()
.clone();
let semantic = placement.element;
send(&mut app, Message::SelectNode(placement.id));
let before = app.project().clone();
for distance in [40., 80.] {
send(
&mut app,
Message::MoveNode(
placement.id,
Position {
x: placement.position.x + distance,
y: placement.position.y + distance,
},
),
);
assert_eq!(app.selected, semantic);
assert_eq!(app.selected_node, Some(placement.id));
assert_eq!(
app.draft.as_ref().unwrap().kind,
crate::forms::RecordKind::Element
);
send(&mut app, Message::SelectNode(placement.id));
assert_eq!(app.selected, semantic);
}
send(&mut app, Message::Undo);
send(&mut app, Message::Undo);
assert_eq!(app.project(), &before);
// Explicit placement inspection must not make its canvas card unselectable.
send(&mut app, Message::Select(placement.id));
send(&mut app, Message::SelectNode(placement.id));
assert_eq!(app.selected, semantic);
send(
&mut app,
Message::Field("/name".into(), "Still editable after dragging".into()),
);
send(&mut app, Message::SelectNode(placement.id));
assert_eq!(
app.draft.as_ref().unwrap().inputs["/name"].raw,
"Still editable after dragging"
);
send(&mut app, Message::Apply);
assert_eq!(
app.project().elements[&semantic].name,
"Still editable after dragging"
);
}
#[test]
fn placement_identity_edit_then_drag_and_diagram_identity_then_arrange() {
let mut app = App::with_project(fixture());