code: def _filter_hovered_items(self, items, event):
          items = self._filter_library_state(items)
          if not items:
              return items
          top_most_item = items[0]
          second_top_most_item = items[1] if len(items) > 1 else None
          first_state_v = next(filter(lambda item: isinstance(item, (NameView, StateView)), items))
          first_state_v = first_state_v.parent if isinstance(first_state_v, NameView) else first_state_v
          if first_state_v:
              for item in items:
                  if isinstance(item, ConnectionView):
                      if self.view.canvas.get_parent(top_most_item) is not first_state_v:
                          continue
                  break
              port_beneath_cursor = False
              state_ports = first_state_v.get_all_ports()
              position = self.view.get_matrix_v2i(first_state_v).transform_point(event.x, event.y)
              i2v_matrix = self.view.get_matrix_i2v(first_state_v)
              for port_v in state_ports:
                  item_distance = port_v.port.glue(position)[1]
                  view_distance = i2v_matrix.transform_distance(item_distance, 0)[0]
                  if view_distance == 0:
                      port_beneath_cursor = True
                      break
              if port_beneath_cursor:
                  items = self.dismiss_upper_items(items, item)
                  top_most_item = items[0]
                  second_top_most_item = items[1] if len(items) > 1 else None
          if isinstance(top_most_item, NameView):
              state_v = second_top_most_item
              if state_v not in self.view.selected_items and top_most_item not in self.view.selected_items:
                  items = items[1:]
          return items