@@ -138,8 +138,9 @@ impl DocumentMessageHandler {
138138 }
139139
140140 /// Returns the paths to all layers in order, optionally including only selected layers
141- fn get_sorted_layers ( & self , only_selected : bool ) -> Vec < Vec < LayerId > > {
141+ fn layers_sorted ( & self , only_selected : bool ) -> Vec < Vec < LayerId > > {
142142 // Compute the indices for each layer to be able to sort them
143+ // TODO: Replace with drain_filter https://github.com/rust-lang/rust/issues/59618
143144 let mut layers_with_indices: Vec < ( Vec < LayerId > , Vec < usize > ) > = self
144145 . active_document ( )
145146 . layer_data
@@ -152,7 +153,7 @@ impl DocumentMessageHandler {
152153 // Once this problem is solved this code can be simplified
153154 match self . active_document ( ) . document . indices_for_path ( & path) {
154155 Err ( err) => {
155- warn ! ( "get_sorted_layers : Could not get indices for the layer {:?}: {:?}" , path, err) ;
156+ warn ! ( "layers_sorted : Could not get indices for the layer {:?}: {:?}" , path, err) ;
156157 None
157158 }
158159 Ok ( indices) => Some ( ( path, indices) ) ,
@@ -165,13 +166,13 @@ impl DocumentMessageHandler {
165166 }
166167
167168 /// Returns the paths to all layers in order
168- fn get_all_layers_sorted ( & self ) -> Vec < Vec < LayerId > > {
169- self . get_sorted_layers ( false )
169+ fn all_layers_sorted ( & self ) -> Vec < Vec < LayerId > > {
170+ self . layers_sorted ( false )
170171 }
171172
172173 /// Returns the paths to all selected layers in order
173- fn get_selected_layers_sorted ( & self ) -> Vec < Vec < LayerId > > {
174- self . get_sorted_layers ( true )
174+ fn selected_layers_sorted ( & self ) -> Vec < Vec < LayerId > > {
175+ self . layers_sorted ( true )
175176 }
176177}
177178
@@ -348,20 +349,19 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
348349 responses. extend ( self . handle_folder_changed ( path) ) ;
349350 }
350351 DeleteSelectedLayers => {
351- // TODO: Replace with drain_filter https://github.com/rust-lang/rust/issues/59618
352- let paths: Vec < Vec < LayerId > > = self . active_document ( ) . layer_data . iter ( ) . filter_map ( |( path, data) | data. selected . then ( || path. clone ( ) ) ) . collect ( ) ;
352+ let paths = self . selected_layers_sorted ( ) ;
353353 for path in paths {
354354 self . active_document_mut ( ) . layer_data . remove ( & path) ;
355355 responses. push_back ( DocumentOperation :: DeleteLayer { path } . into ( ) )
356356 }
357357 }
358358 DuplicateSelectedLayers => {
359- for path in self . active_document ( ) . layer_data . iter ( ) . filter_map ( | ( path , data ) | data . selected . then ( || path . clone ( ) ) ) {
359+ for path in self . selected_layers_sorted ( ) {
360360 responses. push_back ( DocumentOperation :: DuplicateLayer { path } . into ( ) )
361361 }
362362 }
363363 CopySelectedLayers => {
364- let paths: Vec < Vec < LayerId > > = self . get_selected_layers_sorted ( ) ;
364+ let paths = self . selected_layers_sorted ( ) ;
365365 self . copy_buffer . clear ( ) ;
366366 for path in paths {
367367 match self . active_document ( ) . document . layer ( & path) . map ( |t| t. clone ( ) ) {
@@ -551,7 +551,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
551551 responses. push_back ( FrontendMessage :: SetCanvasRotation { new_radians : new } . into ( ) ) ;
552552 }
553553 NudgeSelectedLayers ( x, y) => {
554- let paths: Vec < Vec < LayerId > > = self . get_selected_layers_sorted ( ) ;
554+ let paths: Vec < Vec < LayerId > > = self . selected_layers_sorted ( ) ;
555555
556556 let delta = {
557557 let root_layer_rotation = self . layerdata_mut ( & [ ] ) . rotation ;
@@ -567,10 +567,10 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
567567 }
568568 }
569569 ReorderSelectedLayer ( delta) => {
570- let mut paths: Vec < Vec < LayerId > > = self . get_selected_layers_sorted ( ) ;
570+ let mut paths: Vec < Vec < LayerId > > = self . selected_layers_sorted ( ) ;
571571 // TODO: Support moving more than one layer
572572 if paths. len ( ) == 1 {
573- let all_layer_paths = self . get_all_layers_sorted ( ) ;
573+ let all_layer_paths = self . all_layers_sorted ( ) ;
574574
575575 let max_index = all_layer_paths. len ( ) as i64 - 1 ;
576576
0 commit comments