@@ -385,25 +385,60 @@ def mousePressEvent(self, event):
385385 return
386386
387387 items = self ._items_near (map_pos , None , 20 , 20 )
388- nodes = [i for i in items if isinstance (i , AbstractNodeItem )]
389- # pipes = [i for i in items if isinstance(i, PipeItem)]
388+ pipes = []
389+ nodes = []
390+ backdrop = None
391+ for itm in items :
392+ if isinstance (itm , PipeItem ):
393+ pipes .append (itm )
394+ elif isinstance (itm , AbstractNodeItem ):
395+ if isinstance (itm , BackdropNodeItem ):
396+ backdrop = itm
397+ continue
398+ nodes .append (itm )
390399
391400 if nodes :
392401 self .MMB_state = False
393402
403+ # record the node selection as "self.selected_nodes()" is not as
404+ # reliable here.
405+ selection = set ([])
406+
394407 # toggle extend node selection.
395408 if self .LMB_state :
396409 if self .SHIFT_state :
397- for node in nodes :
398- node .selected = not node .selected
410+ if items and backdrop == items [0 ]:
411+ backdrop .selected = not backdrop .selected
412+ if backdrop .selected :
413+ selection .add (backdrop )
414+ for n in backdrop .get_nodes ():
415+ n .selected = backdrop .selected
416+ if backdrop .selected :
417+ selection .add (n )
418+ else :
419+ for node in nodes :
420+ node .selected = not node .selected
421+ if node .selected :
422+ selection .add (node )
399423 elif self .CTRL_state :
424+ if items and backdrop == items [0 ]:
425+ backdrop .selected = False
426+ else :
427+ for node in nodes :
428+ node .selected = False
429+ else :
430+ if backdrop :
431+ selection .add (backdrop )
432+ for n in backdrop .get_nodes ():
433+ selection .add (n )
400434 for node in nodes :
401- node .selected = False
435+ if node .selected :
436+ selection .add (node )
437+
438+ selection .update (self .selected_nodes ())
402439
403440 # update the recorded node positions.
404- self ._node_positions .update (
405- {n : n .xy_pos for n in self .selected_nodes ()}
406- )
441+ self ._node_positions .update ({n : n .xy_pos for n in selection })
407442
408443 # show selection selection marquee.
409444 if self .LMB_state and not items :
0 commit comments