protected void initPatchViewer() {
    myPanel.setPersistentNotifications(DiffUtil.createCustomNotifications(null, myContext, myPatchRequest));
    final Document outputDocument = myResultEditor.getDocument();
    boolean success =
      DiffUtil.executeWriteCommand(outputDocument, myProject, DiffBundle.message("message.init.merge.content.command"), () -> {
        outputDocument.setText(myPatchRequest.getLocalContent());
        if (!isReadOnly()) DiffUtil.putNonundoableOperation(myProject, outputDocument);
      });
    if (!success && !StringUtil.equals(outputDocument.getText(), myPatchRequest.getLocalContent())) {
      myPanel.setErrorContent(VcsBundle.message("patch.apply.display.local.content.was.modified.error"));
      return;
    }


    PatchChangeBuilder.AppliedPatchState state = new PatchChangeBuilder().buildFromApplied(myPatchRequest.getPatch().getHunks());


    Document patchDocument = myPatchEditor.getDocument();
    WriteAction.run(() -> patchDocument.setText(state.getPatchContent()));

    LineNumberConvertor convertor1 = state.getLineConvertor1();
    LineNumberConvertor convertor2 = state.getLineConvertor2();
    myPatchEditor.getGutter().setLineNumberConverter(new LineNumberConverterAdapter(convertor1.createConvertor()),
                                                     new LineNumberConverterAdapter(convertor2.createConvertor()));

    state.getSeparatorLines().forEach(line -> {
      int offset = patchDocument.getLineStartOffset(line);
      DiffDrawUtil.createLineSeparatorHighlighter(myPatchEditor, offset, offset);
    });

    List<PatchChangeBuilder.AppliedHunk> hunks = state.getHunks();

    int[] modelToPatchIndexes = DiffUtil.getSortedIndexes(hunks, (h1, h2) -> {
      LineRange lines1 = h1.getAppliedToLines();
      LineRange lines2 = h2.getAppliedToLines();
      if (lines1 == null && lines2 == null) return 0;
      if (lines1 == null) return -1;
      if (lines2 == null) return 1;
      return lines1.start - lines2.start;
    });
    int[] patchToModelIndexes = DiffUtil.invertIndexes(modelToPatchIndexes);

    List<LineRange> modelRanges = new ArrayList<>();
    for (int modelIndex = 0; modelIndex < hunks.size(); modelIndex++) {
      int patchIndex = modelToPatchIndexes[modelIndex];
      PatchChangeBuilder.AppliedHunk hunk = hunks.get(patchIndex);
      LineRange resultRange = hunk.getAppliedToLines();

      ApplyPatchChange change = new ApplyPatchChange(hunk, modelIndex, this);

      myModelChanges.add(change);
      if (resultRange != null) myResultChanges.add(change);

      modelRanges.add(resultRange != null ? resultRange : new LineRange(-1, -1));
    }
    myModel.setChanges(modelRanges);

    for (int index : patchToModelIndexes) {
      myPatchChanges.add(myModelChanges.get(index));
    }


    myFoldingModel.install(myResultChanges, getFoldingModelSettings());

    for (ApplyPatchChange change : myModelChanges) {
      change.reinstallHighlighters();
    }
    myStatusPanel.update();


    myContentPanel.setPainter(new MyDividerPainter());

    VisibleAreaListener areaListener = (e) -> myContentPanel.repaint();
    myResultEditor.getScrollingModel().addVisibleAreaListener(areaListener);
    myPatchEditor.getScrollingModel().addVisibleAreaListener(areaListener);

    myPatchEditor.getGutterComponentEx().revalidateMarkup();


    if (myResultChanges.size() > 0) {
      scrollToChange(myResultChanges.get(0), Side.LEFT, true);
    }
  }
protected void initPatchViewer()