def test_base_functions(self): # direction FORWARD (start, end) = get_domobj_range(content=self.case1, position=1, identify_fun=Heading.identify_heading) self.assertEqual((start, end), (1, 3)) (start, end) = get_domobj_range(content=self.case1, position=3, direction=Direction.BACKWARD, \ identify_fun=Heading.identify_heading) self.assertEqual((start, end), (1, 3))
def find_heading(self, position=0, direction=Direction.FORWARD, heading=Heading, connect_with_document=True): u""" Find heading in the given direction :postition: starting line, counting from 0 (in vim you start counting from 1, don't forget) :direction: downwards == Direction.FORWARD, upwards == Direction.BACKWARD :heading: Heading class from which new heading objects will be instanciated :connect_with_document: if True, the newly created heading will be connected with the document, otherwise not :returns: New heading object or None """ (start, end) = get_domobj_range(content=self._content, position=position, direction=direction, identify_fun=heading.identify_heading) if start is not None and end is None: end = len(self._content) - 1 if start is not None and end is not None: return heading.parse_heading_from_data( self._content[start:end + 1], self.get_all_todo_states(), document=self if connect_with_document else None, orig_start=start)
def find_checkbox(self, position=0, direction=Direction.FORWARD, checkbox=Checkbox, connect_with_heading=True): u""" Find checkbox in the given direction :postition: starting line, counting from 0 (in vim you start counting from 1, don't forget) :direction: downwards == Direction.FORWARD, upwards == Direction.BACKWARD :checkbox: Checkbox class from which new checkbox objects will be instanciated :connect_with_heading: if True, the newly created checkbox will be connected with the heading, otherwise not :returns: New checkbox object or None """ doc = self.document (start, end) = get_domobj_range(content=doc._content, position=position, direction=direction, identify_fun=checkbox.identify_checkbox) # if out of current headinig range, reutrn None heading_end = self.start + len(self) - 1 if start is not None and start > heading_end: return None if end is not None and end > heading_end: end = heading_end if start is not None and end is None: end = heading_end if start is not None and end is not None: return checkbox.parse_checkbox_from_data( doc._content[start:end + 1], heading=self if connect_with_heading else None, orig_start=start)
def find_checkbox(self, position=0, direction=Direction.FORWARD, checkbox=Checkbox, connect_with_heading=True): u""" Find checkbox in the given direction :postition: starting line, counting from 0 (in vim you start counting from 1, don't forget) :direction: downwards == Direction.FORWARD, upwards == Direction.BACKWARD :checkbox: Checkbox class from which new checkbox objects will be instanciated :connect_with_heading: if True, the newly created checkbox will be connected with the heading, otherwise not :returns: New checkbox object or None """ doc = self.document (start, end) = get_domobj_range(content=doc._content, position=position, direction=direction, identify_fun=checkbox.identify_checkbox) # if out of current headinig range, reutrn None heading_end = self.start + len(self) - 1 if start is not None and start > heading_end: return None if end is not None and end > heading_end: end = heading_end if start is not None and end is None: end = heading_end if start is not None and end is not None: return checkbox.parse_checkbox_from_data( doc._content[start:end + 1], heading=self if connect_with_heading else None, orig_start=start)
def find_heading(self, position=0, direction=Direction.FORWARD, heading=Heading, connect_with_document=True): u""" Find heading in the given direction Args: position (int): starting line, counting from 0 (in vim you start counting from 1, don't forget) direction: downwards == Direction.FORWARD, upwards == Direction.BACKWARD heading: Heading class from which new heading objects will be instanciated connect_with_document: if True, the newly created heading will be connected with the document, otherwise not Returns: heading or None: New heading """ start, end = get_domobj_range( content=self._content, position=position, direction=direction, identify_fun=heading.identify_heading ) if start is None: return None if end is None: end = len(self._content) - 1 document = self if connect_with_document else None return heading.parse_heading_from_data( self._content[start : end + 1], self.get_all_todo_states(), document=document, orig_start=start )