use of com.intellij.diff.tools.fragmented.LineNumberConvertor in project intellij-community by JetBrains.
the class ApplyPatchViewer method initPatchViewer.
//
// Impl
//
protected void initPatchViewer() {
final Document outputDocument = myResultEditor.getDocument();
boolean success = DiffUtil.executeWriteCommand(outputDocument, myProject, "Init merge content", () -> {
outputDocument.setText(myPatchRequest.getLocalContent());
if (!isReadOnly())
DiffUtil.putNonundoableOperation(myProject, outputDocument);
});
if (!success && !StringUtil.equals(outputDocument.getText(), myPatchRequest.getLocalContent())) {
myPanel.setErrorContent("Failed to display patch applier - local content was modified");
return;
}
PatchChangeBuilder builder = new PatchChangeBuilder();
builder.exec(myPatchRequest.getPatch().getHunks());
Document patchDocument = myPatchEditor.getDocument();
patchDocument.setText(builder.getPatchContent());
LineNumberConvertor convertor1 = builder.getLineConvertor1();
LineNumberConvertor convertor2 = builder.getLineConvertor2();
myPatchEditor.getGutterComponentEx().setLineNumberConvertor(convertor1.createConvertor(), convertor2.createConvertor());
TIntArrayList lines = builder.getSeparatorLines();
for (int i = 0; i < lines.size(); i++) {
int offset = patchDocument.getLineStartOffset(lines.get(i));
DiffDrawUtil.createLineSeparatorHighlighter(myPatchEditor, offset, offset, BooleanGetter.TRUE);
}
List<PatchChangeBuilder.Hunk> hunks = builder.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.Hunk 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);
}
}
Aggregations