def jump_to_line_index(self, index):
        """Ensure the line indicated by index is visible."""
        ### retrieve number of lines and use it to define
        ### the maximum and minimum possible values
        ### for indices

        length = len(self.lines)

        max_value = length - 1
        min_value = -length

        ### clamp index
        clamped_index = min(max(index, min_value), max_value)

        ### check whether the line from the clamped index is
        ### visible in the scroll area;
        ###
        ### if it is not, adjust the position of the text
        ### (all the lines), so the line is visible

        ## obtain the rect of the line
        line_rect = self.lines[clamped_index].rect

        ## if the line's bottom is below the scroll area's
        ## bottom, move the text so the line has its bottom
        ## aligned to the bottom of the scroll area

        if line_rect.bottom > self.scroll_area.bottom:

            y_delta = self.scroll_area.bottom - line_rect.bottom

            self.lines.rect.move_ip(0, y_delta)

        ## if the line's top is above the scroll area's
        ## top, move the text so the line has its top
        ## aligned to the top of the scroll area

        elif line_rect.top < self.scroll_area.top:

            y_delta = self.scroll_area.top - line_rect.top
            self.lines.rect.move_ip(0, y_delta)
Ensure the line indicated by index is visible.
nodezator/textman/viewer/prep.py