code: def translate_row_col_to_index(self, row, col):
          
          try:
              result = self._line_start_indexes[row]
              line = self.lines[row]
          except IndexError:
              if row < 0:
                  result = self._line_start_indexes[0]
                  line = self.lines[0]
              else:
                  result = self._line_start_indexes[-1]
                  line = self.lines[-1]
  
          result += max(0, min(col, len(line)))
  
          # Keep in range. (len(self.text) is included, because the cursor can be
          # right after the end of the text as well.)
          result = max(0, min(result, len(self.text)))
          return result
docs: Given a (row, col) tuple, return the corresponding index.
          (Row and col params are 0-based.)
  
          Negative row/col values are turned into zero.