@@ -2,7 +2,7 @@ use super::{
22 ChainInsertionPoint , FlowType , GlideOffsets , ImportOrExport , InputConnector , LayerClickTargetTypes , NodeLocator , NodeNetworkInterface , NodeNetworkTemplate , NodePersistentMetadata , NodePosition ,
33 NodeTemplate , NodeTemplateImplementation , NodeTypePersistentMetadata , OutputConnector , Previewing , RootNode , TransactionStatus ,
44} ;
5- use crate :: consts:: { GRID_SIZE , STACK_VERTICAL_GAP , WIRE_DRAG_NODE_EXPAND_DELAY_MILLISECONDS } ;
5+ use crate :: consts:: { GRID_SIZE , LAYER_INDENT_OFFSET , STACK_VERTICAL_GAP , WIRE_DRAG_NODE_EXPAND_DELAY_MILLISECONDS } ;
66use crate :: messages:: input_mapper:: utility_types:: pointer:: EditorPointerState ;
77use crate :: messages:: portfolio:: document:: node_graph:: document_node_definitions:: resolve_proto_node_type;
88use crate :: messages:: portfolio:: document:: node_graph:: utility_types:: { ContextMenuData , Direction } ;
@@ -4228,3 +4228,73 @@ async fn grouping_a_group_moves_the_layer_below_it_past_all_of_its_contents() {
42284228 assert_eq ! ( overlapping_layers( & editor) , Vec :: new( ) ) ;
42294229 assert_invariants ( & editor, "after grouping a group" ) ;
42304230}
4231+
4232+ fn indent_below_parent ( editor : & EditorTestUtils , layer : LayerNodeIdentifier ) -> Option < i32 > {
4233+ let interface = & editor. active_document ( ) . network_interface ;
4234+ let parent = layer. parent ( interface. document_metadata ( ) ) ?;
4235+ Some ( interface. position ( & parent. to_node ( ) , & [ ] ) ?. x - interface. position ( & layer. to_node ( ) , & [ ] ) ?. x )
4236+ }
4237+
4238+ #[ tokio:: test]
4239+ async fn reordering_the_layers_of_a_group_keeps_them_indented_below_it ( ) {
4240+ let mut editor = EditorTestUtils :: create ( ) ;
4241+ editor. new_document ( ) . await ;
4242+ editor. handle_message ( new_artboard_message ( NodeId :: new ( ) ) ) . await ;
4243+ for x in [ 0. , 50. , 100. ] {
4244+ editor. draw_rect ( x, 0. , x + 40. , 40. ) . await ;
4245+ }
4246+
4247+ let artboard = LayerNodeIdentifier :: ROOT_PARENT
4248+ . children ( editor. active_document ( ) . metadata ( ) )
4249+ . next ( )
4250+ . expect ( "the artboard should be a layer" ) ;
4251+ let top_two = artboard. children ( editor. active_document ( ) . metadata ( ) ) . take ( 2 ) . map ( LayerNodeIdentifier :: to_node) . collect ( ) ;
4252+ editor. handle_message ( NodeGraphMessage :: SelectedNodesSet { nodes : top_two } ) . await ;
4253+ group_selected_layers ( & mut editor) . await ;
4254+
4255+ let group = artboard
4256+ . children ( editor. active_document ( ) . metadata ( ) )
4257+ . next ( )
4258+ . expect ( "the group should be the top layer of the artboard" ) ;
4259+ for insert_index in [ 0 , 2 ] {
4260+ let moved = group. children ( editor. active_document ( ) . metadata ( ) ) . nth ( 1 - insert_index / 2 ) . expect ( "the group should hold two layers" ) ;
4261+ editor. handle_message ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ moved. to_node( ) ] } ) . await ;
4262+ editor. handle_message ( DocumentMessage :: MoveSelectedLayersTo { parent : group, insert_index } ) . await ;
4263+
4264+ for layer in group. children ( editor. active_document ( ) . metadata ( ) ) . chain ( [ group] ) {
4265+ assert_eq ! ( indent_below_parent( & editor, layer) , Some ( LAYER_INDENT_OFFSET ) , "moving a layer to index {insert_index} of the group" ) ;
4266+ }
4267+ }
4268+ assert_eq ! ( overlapping_layers( & editor) , Vec :: new( ) ) ;
4269+ }
4270+
4271+ #[ tokio:: test]
4272+ async fn releasing_a_drag_of_a_layer_in_a_stack_leaves_every_layer_where_the_drag_drew_it ( ) {
4273+ let mut editor = EditorTestUtils :: create ( ) ;
4274+ editor. new_document ( ) . await ;
4275+ editor. handle_message ( new_artboard_message ( NodeId :: new ( ) ) ) . await ;
4276+ for x in [ 0. , 50. , 100. , 150. ] {
4277+ editor. draw_rect ( x, 0. , x + 40. , 40. ) . await ;
4278+ }
4279+ let artboard = LayerNodeIdentifier :: ROOT_PARENT
4280+ . children ( editor. active_document ( ) . metadata ( ) )
4281+ . next ( )
4282+ . expect ( "the artboard should be a layer" ) ;
4283+ let third = artboard. children ( editor. active_document ( ) . metadata ( ) ) . nth ( 2 ) . expect ( "the artboard should hold four layers" ) ;
4284+ editor. handle_message ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ third. to_node( ) ] } ) . await ;
4285+
4286+ let interface = & mut editor. active_document_mut ( ) . network_interface ;
4287+ let layers: Vec < NodeId > = interface. document_network ( ) . nodes . keys ( ) . copied ( ) . filter ( |node_id| interface. is_layer ( node_id, & [ ] ) ) . collect ( ) ;
4288+ for keep_upstream in [ false , true ] {
4289+ for offset in [ IVec2 :: new ( 0 , 3 ) , IVec2 :: new ( 0 , -2 ) , IVec2 :: new ( 5 , 0 ) ] {
4290+ let before = interface. positions ( layers. iter ( ) . copied ( ) , & [ ] ) ;
4291+ interface. drag_selected_nodes ( offset, keep_upstream, & [ ] ) ;
4292+ let dragging = interface. positions ( layers. iter ( ) . copied ( ) , & [ ] ) ;
4293+ interface. finish_drag ( & [ ] ) ;
4294+
4295+ assert_ne ! ( dragging, before, "dragging by {offset} keeping upstream: {keep_upstream} should move the layers" ) ;
4296+
4297+ assert_eq ! ( interface. positions( layers. iter( ) . copied( ) , & [ ] ) , dragging, "dragging by {offset} keeping upstream: {keep_upstream}" ) ;
4298+ }
4299+ }
4300+ }
0 commit comments