def get_range_for_next_item_in_html(tag, offset, sel_start, sel_end): """ Returns range for item to be selected in tag after current caret position @param tag: Tag declaration @type tag: str @param offset: Tag's position index inside content @type offset: int @param sel_start: Start index of user selection @type sel_start: int @param sel_end: End index of user selection @type sel_end: int @return List with two indexes if next item was found, None otherwise """ tokens = parser_utils.parse_html(tag, offset) next = [] # search for token that is right to selection for i, token in enumerate(tokens): if token['type'] in known_xml_types: # check token position pos_test = token['start'] >= sel_start if token['type'] == 'xml-attribute' and is_quote( token['content'][0]): pos_test = token['start'] + 1 >= sel_start and token[ 'end'] - 1 != sel_end if not pos_test and not (sel_start == sel_end and token['end'] > sel_start): continue # found token that should be selected if token['type'] == 'xml-attname': next = handle_full_attribute_html( tokens, i, sel_end <= token['end'] and token['start'] or -1) if next: return next elif token['end'] > sel_end: next = [token['start'], token['end']] if token['type'] == 'xml-attribute': next = handle_quotes_html(token['content'], next) if sel_start == next[0] and sel_end == next[1]: # in case of empty attribute continue return next return None
def get_range_for_next_item_in_html(tag, offset, sel_start, sel_end): """ Returns range for item to be selected in tag after current caret position @param tag: Tag declaration @type tag: str @param offset: Tag's position index inside content @type offset: int @param sel_start: Start index of user selection @type sel_start: int @param sel_end: End index of user selection @type sel_end: int @return List with two indexes if next item was found, None otherwise """ tokens = parser_utils.parse_html(tag, offset) next = [] # search for token that is right to selection for i, token in enumerate(tokens): if token['type'] in known_xml_types: # check token position pos_test = token['start'] >= sel_start if token['type'] == 'xml-attribute' and is_quote(token['content'][0]): pos_test = token['start'] + 1 >= sel_start and token['end'] -1 != sel_end if not pos_test and not (sel_start == sel_end and token['end'] > sel_start): continue # found token that should be selected if token['type'] == 'xml-attname': next = handle_full_attribute_html(tokens, i, sel_end <= token['end'] and token['start'] or -1) if next: return next elif token['end'] > sel_end: next = [token['start'], token['end']] if token['type'] == 'xml-attribute': next = handle_quotes_html(token['content'], next) if sel_start == next[0] and sel_end == next[1]: # in case of empty attribute continue return next return None
def get_range_for_prev_item_in_html(tag, offset, sel_start, sel_end): """ Returns range for item to be selected in tag before current caret position @param tag: Tag declaration @type tag: str @param offset: Tag's position index inside content @type offset: int @param sel_start: Start index of user selection @type sel_start: int @param sel_end: End index of user selection @type sel_end: int @return List with two indexes if next item was found, None otherwise """ tokens = parser_utils.parse_html(tag, offset) # search for token that is left to the selection for i in range(len(tokens) - 1, -1, -1): token = tokens[i] if token['type'] in known_xml_types: # check token position pos_test = token['start'] < sel_start if token['type'] == 'xml-attribute' and is_quote( token['content'][0]): pos_test = token['start'] + 1 < sel_start if not pos_test: continue # found token that should be selected if token['type'] == 'xml-attname': next = handle_full_attribute_html(tokens, i, token['start']) if next: return next else: next = [token['start'], token['end']] if token['type'] == 'xml-attribute': next = handle_quotes_html(token['content'], next) return next return None
def get_range_for_prev_item_in_html(tag, offset, sel_start, sel_end): """ Returns range for item to be selected in tag before current caret position @param tag: Tag declaration @type tag: str @param offset: Tag's position index inside content @type offset: int @param sel_start: Start index of user selection @type sel_start: int @param sel_end: End index of user selection @type sel_end: int @return List with two indexes if next item was found, None otherwise """ tokens = parser_utils.parse_html(tag, offset) # search for token that is left to the selection for i in range(len(tokens) - 1, -1, -1): token = tokens[i] if token['type'] in known_xml_types: # check token position pos_test = token['start'] < sel_start if token['type'] == 'xml-attribute' and is_quote(token['content'][0]): pos_test = token['start'] + 1 < sel_start if not pos_test: continue # found token that should be selected if token['type'] == 'xml-attname': next = handle_full_attribute_html(tokens, i, token['start']) if next: return next else: next = [token['start'], token['end']] if token['type'] == 'xml-attribute': next = handle_quotes_html(token['content'], next) return next return None