private void replaceRanges(
     @NotNull List<Range> rangesInChange, @NotNull List<Range> newRangesInChange) {
   for (Range range : rangesInChange) {
     if (range.getHighlighter() != null) {
       range.getHighlighter().dispose();
     }
     range.setHighlighter(null);
     range.invalidate();
   }
   for (Range range : newRangesInChange) {
     range.setHighlighter(createHighlighter(range));
   }
 }
  private void doUpdateRanges(
      int beforeChangedLine1,
      int beforeChangedLine2,
      int linesShift, // before -> after
      int beforeTotalLines,
      @NotNull List<Range> rangesBefore,
      @NotNull List<Range> changedRanges,
      @NotNull List<Range> rangesAfter) {
    try {
      int vcsTotalLines = getLineCount(myVcsDocument);

      Range lastRangeBefore = ContainerUtil.getLastItem(rangesBefore);
      Range firstRangeAfter = ContainerUtil.getFirstItem(rangesAfter);

      //noinspection UnnecessaryLocalVariable
      int afterChangedLine1 = beforeChangedLine1;
      int afterChangedLine2 = beforeChangedLine2 + linesShift;

      int vcsLine1 = getVcsLine1(lastRangeBefore, beforeChangedLine1);
      int vcsLine2 =
          getVcsLine2(firstRangeAfter, beforeChangedLine2, beforeTotalLines, vcsTotalLines);

      List<Range> newChangedRanges =
          getNewChangedRanges(afterChangedLine1, afterChangedLine2, vcsLine1, vcsLine2);

      shiftRanges(rangesAfter, linesShift);

      if (!changedRanges.equals(newChangedRanges)) {
        replaceRanges(changedRanges, newChangedRanges);

        myRanges =
            new ArrayList<Range>(
                rangesBefore.size() + newChangedRanges.size() + rangesAfter.size());

        myRanges.addAll(rangesBefore);
        myRanges.addAll(newChangedRanges);
        myRanges.addAll(rangesAfter);

        for (Range range : myRanges) {
          if (!range.hasHighlighter()) range.setHighlighter(createHighlighter(range));
        }

        if (myRanges.isEmpty()) {
          markFileUnchanged();
        }
      }
    } catch (ProcessCanceledException ignore) {
    } catch (FilesTooBigForDiffException e1) {
      installAnathema();
      removeHighlightersFromMarkupModel();
    }
  }
  private void reinstallRanges() {
    myApplication.assertIsDispatchThread();

    synchronized (myLock) {
      if (myReleased) return;

      removeAnathema();
      removeHighlightersFromMarkupModel();
      try {
        myRanges = new RangesBuilder(myDocument, myVcsDocument, myMode).getRanges();
      } catch (FilesTooBigForDiffException e) {
        installAnathema();
        return;
      }
      for (final Range range : myRanges) {
        range.setHighlighter(createHighlighter(range));
      }
    }
  }