Do not adjust node position when created under mouse cursor. (#7136)

Fixes #7064

Because our position adjusting mechanism was very confusing for users, especially on edge drops, this PR disables this adjusting for the cases where node is about to be put under the mouse pointer.
This commit is contained in:
Adam Obuchowicz 2023-06-29 14:24:41 +02:00 committed by GitHub
parent bf5ddf3de0
commit 24bdb1cf8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -3710,6 +3710,8 @@ mod tests {
}
#[test]
// The alignment is disabled for mouse-oriented node placement. See [`new_node_position`] docs.
#[ignore]
fn test_magnet_alignment_when_adding_node_by_shortcut() {
test_magnet_alignment_when_adding_node(move_mouse_and_add_node_by_shortcut);
}

View File

@ -31,6 +31,11 @@ pub mod free_place_finder;
/// Return a position for a newly created node. The position is calculated by establishing a
/// reference position and then aligning it to existing nodes.
///
/// **Note** The aligning nodes is currently disabled for nodes which were created under mouse
/// position (including dropping an edge), as it turned out to be confusing for users. It may be
/// brought back once the algorithm will be improved (the [`at_mouse_aligned_to_close_nodes`]
/// function)
///
/// The reference position is chosen from among:
/// - the position of a source node of the dropped edge (if available),
/// - the bottom-most selected node (if available),
@ -63,13 +68,12 @@ pub fn new_node_position(
AddNodeEvent => default(),
StartCreationEvent | ClickingButton if some_nodes_are_selected =>
under_selected_nodes(graph_editor),
StartCreationEvent => at_mouse_aligned_to_close_nodes(graph_editor, mouse_position),
StartCreationEvent => mouse_position,
ClickingButton => {
let pos = on_ray(graph_editor, screen_center, Vector2(0.0, -1.0)).unwrap();
magnet_alignment(graph_editor, pos, HorizontallyAndVertically)
}
DroppingEdge { endpoint } =>
at_mouse_aligned_to_source_node(graph_editor, endpoint.node_id, mouse_position),
DroppingEdge { .. } => mouse_position,
StartCreationFromPortEvent { endpoint } => under(graph_editor, endpoint.node_id),
}
}