@@ -274,23 +274,23 @@ mod imp {
274274 obj. notify_paintable_rect ( ) ;
275275
276276 // Update selection if paintable rect changed.
277- if let Some ( prev_paintable_rect) = prev_paintable_rect {
278- if let Some ( selection) = obj. selection ( ) {
279- let selection_rect = selection . rect ( ) ;
280-
281- let scale_x = new_paintable_rect . width ( ) / prev_paintable_rect . width ( ) ;
282- let scale_y = new_paintable_rect. height ( ) / prev_paintable_rect. height ( ) ;
283-
284- let rel_x = selection_rect . x ( ) - prev_paintable_rect . x ( ) ;
285- let rel_y = selection_rect. y ( ) - prev_paintable_rect. y ( ) ;
286-
287- obj . set_selection ( Some ( Selection :: from_rect (
288- new_paintable_rect . x ( ) + rel_x * scale_x ,
289- new_paintable_rect. y ( ) + rel_y * scale_y ,
290- selection_rect . width ( ) * scale_x ,
291- selection_rect. height ( ) * scale_y ,
292- ) ) ) ;
293- }
277+ if let Some ( prev_paintable_rect) = prev_paintable_rect
278+ && let Some ( selection) = obj. selection ( )
279+ {
280+ let selection_rect = selection . rect ( ) ;
281+
282+ let scale_x = new_paintable_rect. width ( ) / prev_paintable_rect. width ( ) ;
283+ let scale_y = new_paintable_rect . height ( ) / prev_paintable_rect . height ( ) ;
284+
285+ let rel_x = selection_rect. x ( ) - prev_paintable_rect. x ( ) ;
286+ let rel_y = selection_rect . y ( ) - prev_paintable_rect . y ( ) ;
287+
288+ obj . set_selection ( Some ( Selection :: from_rect (
289+ new_paintable_rect. x ( ) + rel_x * scale_x ,
290+ new_paintable_rect . y ( ) + rel_y * scale_y ,
291+ selection_rect. width ( ) * scale_x ,
292+ selection_rect . height ( ) * scale_y ,
293+ ) ) ) ;
294294 }
295295 }
296296
@@ -444,8 +444,12 @@ impl ViewPort {
444444 return CursorType :: Crosshair ;
445445 } ;
446446
447- let [ top_left_handle, top_right_handle, bottom_right_handle, bottom_left_handle] =
448- imp. selection_handles . get ( ) . unwrap ( ) ;
447+ let [
448+ top_left_handle,
449+ top_right_handle,
450+ bottom_right_handle,
451+ bottom_left_handle,
452+ ] = imp. selection_handles . get ( ) . unwrap ( ) ;
449453
450454 if top_left_handle. contains_point ( & position) {
451455 CursorType :: NorthWestResize
@@ -800,37 +804,36 @@ impl ViewPort {
800804
801805 // The user clicked without dragging. Make up a larger selection
802806 // to reduce confusion.
803- if let Some ( mut selection) = self . selection ( ) {
804- if imp. drag_cursor . get ( ) == CursorType :: Crosshair
805- && selection. end_x == selection. start_x
806- && selection. end_y == selection. start_y
807- {
808- let offset = DEFAULT_SELECTION_SIZE / 2.0 ;
809- selection. start_x -= offset;
810- selection. start_y -= offset;
811- selection. end_x += offset;
812- selection. end_y += offset;
813-
814- let selection_rect = selection. rect ( ) ;
815-
816- // Keep the coordinates inside the paintable rect.
817- if selection. start_x < paintable_rect. x ( ) {
818- selection. start_x = paintable_rect. x ( ) ;
819- selection. end_x = selection. start_x + selection_rect. width ( ) ;
820- } else if selection. end_x > paintable_rect. width ( ) + paintable_rect. x ( ) {
821- selection. end_x = paintable_rect. width ( ) + paintable_rect. x ( ) ;
822- selection. start_x = selection. end_x - selection_rect. width ( ) ;
823- }
824- if selection. start_y < paintable_rect. y ( ) {
825- selection. start_y = paintable_rect. y ( ) ;
826- selection. end_y = selection. start_y + selection_rect. height ( ) ;
827- } else if selection. end_y > paintable_rect. height ( ) + paintable_rect. y ( ) {
828- selection. end_y = paintable_rect. height ( ) + paintable_rect. y ( ) ;
829- selection. start_y = selection. end_y - selection_rect. height ( ) ;
830- }
831-
832- self . set_selection ( Some ( selection) ) ;
807+ if let Some ( mut selection) = self . selection ( )
808+ && imp. drag_cursor . get ( ) == CursorType :: Crosshair
809+ && selection. end_x == selection. start_x
810+ && selection. end_y == selection. start_y
811+ {
812+ let offset = DEFAULT_SELECTION_SIZE / 2.0 ;
813+ selection. start_x -= offset;
814+ selection. start_y -= offset;
815+ selection. end_x += offset;
816+ selection. end_y += offset;
817+
818+ let selection_rect = selection. rect ( ) ;
819+
820+ // Keep the coordinates inside the paintable rect.
821+ if selection. start_x < paintable_rect. x ( ) {
822+ selection. start_x = paintable_rect. x ( ) ;
823+ selection. end_x = selection. start_x + selection_rect. width ( ) ;
824+ } else if selection. end_x > paintable_rect. width ( ) + paintable_rect. x ( ) {
825+ selection. end_x = paintable_rect. width ( ) + paintable_rect. x ( ) ;
826+ selection. start_x = selection. end_x - selection_rect. width ( ) ;
833827 }
828+ if selection. start_y < paintable_rect. y ( ) {
829+ selection. start_y = paintable_rect. y ( ) ;
830+ selection. end_y = selection. start_y + selection_rect. height ( ) ;
831+ } else if selection. end_y > paintable_rect. height ( ) + paintable_rect. y ( ) {
832+ selection. end_y = paintable_rect. height ( ) + paintable_rect. y ( ) ;
833+ selection. start_y = selection. end_y - selection_rect. height ( ) ;
834+ }
835+
836+ self . set_selection ( Some ( selection) ) ;
834837 }
835838
836839 if let Some ( pointer_position) = imp. pointer_position . get ( ) {
0 commit comments