nodes: 0, module; 1, function_definition; 2, function_name:_filter_library_state; 3, parameters; 4, block; 5, identifier:self; 6, identifier:items; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, comment:# If the hovered item is e.g. a connection, we need to get the parental state; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, comment:"""Filters out child elements of library state when they cannot be hovered
  
          Checks if hovered item is within a LibraryState
          * if not, the list is returned unfiltered
          * if so, STATE_SELECTION_INSIDE_LIBRARY_STATE_ENABLED is checked
              * if enabled, the library is selected (instead of the state copy)
              * if not, the upper most library is selected
  
          :param list items: Sorted list of items beneath the cursor
          :return: filtered items
          :rtype: list
          """; 16, not_operator; 17, block; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, call; 23, comment:# select the library state instead of the library_root_state because it is hidden; 24, block; 25, else_clause; 26, identifier:items; 27, return_statement; 28, identifier:top_most_item; 29, subscript; 30, identifier:top_most_state_v; 31, conditional_expression:top_most_item if isinstance(top_most_item, StateView) else top_most_item.parent; 32, identifier:state; 33, attribute; 34, identifier:global_gui_config; 35, attribute; 36, attribute; 37, argument_list; 38, if_statement; 39, return_statement; 40, comment:# Find state_copy of uppermost LibraryState; 41, block; 42, identifier:items; 43, identifier:items; 44, integer:0; 45, identifier:top_most_item; 46, call; 47, attribute; 48, attribute; 49, identifier:state; 50, identifier:gui_helper_state_machine; 51, identifier:global_gui_config; 52, identifier:global_gui_config; 53, identifier:get_config_value; 54, string; 55, attribute; 56, block; 57, identifier:items; 58, expression_statement; 59, comment:# If the hovered element is a child of a library, make the library the hovered_item; 60, if_statement; 61, return_statement; 62, identifier:isinstance; 63, argument_list; 64, identifier:top_most_item; 65, identifier:parent; 66, identifier:top_most_state_v; 67, identifier:model; 68, string_content:STATE_SELECTION_INSIDE_LIBRARY_STATE_ENABLED; 69, identifier:state; 70, identifier:is_root_state_of_library; 71, expression_statement; 72, return_statement; 73, assignment; 74, identifier:library_root_state; 75, block; 76, identifier:items; 77, identifier:top_most_item; 78, identifier:StateView; 79, assignment; 80, call; 81, identifier:library_root_state; 82, call; 83, expression_statement; 84, expression_statement; 85, return_statement; 86, identifier:new_topmost_item; 87, call; 88, attribute; 89, argument_list; 90, attribute; 91, argument_list; 92, assignment; 93, assignment; 94, call; 95, attribute; 96, argument_list; 97, identifier:self; 98, identifier:dismiss_upper_items; 99, identifier:items; 100, identifier:new_topmost_item; 101, identifier:state; 102, identifier:get_uppermost_library_root_state; 103, identifier:library_state; 104, attribute; 105, identifier:library_state_v; 106, call; 107, attribute; 108, argument_list; 109, attribute; 110, identifier:get_view_for_core_element; 111, attribute; 112, identifier:library_root_state; 113, identifier:parent; 114, attribute; 115, argument_list; 116, identifier:self; 117, identifier:dismiss_upper_items; 118, identifier:items; 119, identifier:library_state_v; 120, attribute; 121, identifier:canvas; 122, identifier:state; 123, identifier:parent; 124, attribute; 125, identifier:get_view_for_core_element; 126, identifier:library_state; 127, identifier:self; 128, identifier:view; 129, attribute; 130, identifier:canvas; 131, identifier:self; 132, identifier:view
code: def _filter_library_state(self, items):
          """Filters out child elements of library state when they cannot be hovered
  
          Checks if hovered item is within a LibraryState
          * if not, the list is returned unfiltered
          * if so, STATE_SELECTION_INSIDE_LIBRARY_STATE_ENABLED is checked
              * if enabled, the library is selected (instead of the state copy)
              * if not, the upper most library is selected
  
          :param list items: Sorted list of items beneath the cursor
          :return: filtered items
          :rtype: list
          """
          if not items:
              return items
  
          top_most_item = items[0]
          # If the hovered item is e.g. a connection, we need to get the parental state
          top_most_state_v = top_most_item if isinstance(top_most_item, StateView) else top_most_item.parent
          state = top_most_state_v.model.state
  
          global_gui_config = gui_helper_state_machine.global_gui_config
          if global_gui_config.get_config_value('STATE_SELECTION_INSIDE_LIBRARY_STATE_ENABLED'):
              # select the library state instead of the library_root_state because it is hidden
              if state.is_root_state_of_library:
                  new_topmost_item = self.view.canvas.get_view_for_core_element(state.parent)
                  return self.dismiss_upper_items(items, new_topmost_item)
              return items
          else:
              # Find state_copy of uppermost LibraryState
              library_root_state = state.get_uppermost_library_root_state()
  
              # If the hovered element is a child of a library, make the library the hovered_item
              if library_root_state:
                  library_state = library_root_state.parent
                  library_state_v = self.view.canvas.get_view_for_core_element(library_state)
                  return self.dismiss_upper_items(items, library_state_v)
              return items