private IntPair calculateTextPreferredWidth(int startVisualLine, int endVisualLine) {
    if (checkDirty()) {
      return new IntPair(1, 0);
    }
    assertValidState();
    VisualLinesIterator iterator = new VisualLinesIterator(myEditor, startVisualLine);
    int maxWidth = 0;
    int largestLineNumber = 0;
    int caretVisualLine = myEditor.getCaretModel().getVisualPosition().line;
    while (!iterator.atEnd()) {
      int visualLine = iterator.getVisualLine();
      int width = getVisualLineWidth(iterator, visualLine != caretVisualLine);
      if (width > maxWidth) {
        maxWidth = width;
        largestLineNumber = visualLine;
      }
      if (visualLine >= endVisualLine) break;
      iterator.advance();
    }
    return new IntPair(maxWidth, largestLineNumber);
  }
private IntPair calculateTextPreferredWidth(int startVisualLine, int endVisualLine)