def xml_node_at_pos(self, pos): import koXMLTreeService self.xml_parse() tree = self._xml_tree_cache if not tree: return None line, col = self.accessor.line_and_col_at_pos(pos) node = tree.locateNode(line, col) # XXX this needs to be worked out better last_start = self.accessor.text.rfind("<", 0, pos) last_end = self.accessor.text.find(">", last_start, pos) if node is None and last_start >= 0: node = koXMLTreeService.elementFromText(tree, self.accessor.text[last_start:last_end], node) if node is None or node.start is None: return node # elementtree line numbers are 1 based, convert to zero based node_pos = self.accessor.pos_from_line_and_col(node.start[0] - 1, node.start[1]) if last_end == -1 and last_start != node_pos: # print "try parse ls %d le %d np %d pos %d %r" % (last_start, last_end, node_pos, pos, accessor.text[last_start:pos]) # we have a dirty tree, need to create a current node and add it newnode = koXMLTreeService.elementFromText(tree, self.accessor.text[last_start:pos], node) if newnode is not None: return newnode return node
def xml_node_at_pos(self, pos): import koXMLTreeService self.xml_parse() tree = self._xml_tree_cache if not tree: return None line, col = self.accessor.line_and_col_at_pos(pos) node = tree.locateNode(line, col) # XXX this needs to be worked out better last_start = self.accessor.text.rfind('<', 0, pos) last_end = self.accessor.text.find('>', last_start, pos) if node is None and last_start >= 0: node = koXMLTreeService.elementFromText( tree, self.accessor.text[last_start:last_end], node) if node is None or node.start is None: return node # elementtree line numbers are 1 based, convert to zero based node_pos = self.accessor.pos_from_line_and_col( node.start[0]-1, node.start[1]) if last_end == -1 and last_start != node_pos: # print "try parse ls %d le %d np %d pos %d %r" % (last_start, last_end, node_pos, pos, accessor.text[last_start:pos]) # we have a dirty tree, need to create a current node and add it newnode = koXMLTreeService.elementFromText( tree, self.accessor.text[last_start:pos], node) if newnode is not None: return newnode return node