use of com.intellij.openapi.editor.event.VisibleAreaListener in project intellij-community by JetBrains.
the class DiffPanelImpl method onContentChangedIn.
public void onContentChangedIn(EditorSource source) {
myDiffUpdater.contentRemoved(source);
final EditorEx editor = source.getEditor();
if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) {
editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
}
DiffSideView viewSide = getSideView(source.getSide());
viewSide.setEditorSource(getProject(), source);
Disposer.dispose(myScrollSupport);
if (editor == null) {
if (!myDisposed) {
rediff();
}
return;
}
final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance());
myDiffUpdater.contentAdded(source);
editor.getSettings().setLineNumbersShown(true);
editor.getSettings().setFoldingOutlineShown(false);
editor.getFoldingModel().setFoldingEnabled(false);
((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
Editor editor1 = getEditor(FragmentSide.SIDE1);
Editor editor2 = getEditor(FragmentSide.SIDE2);
if (editor1 != null && editor2 != null && myIsSyncScroll) {
myScrollSupport.install(new EditingSides[] { this });
}
final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener();
final ScrollingModel scrollingModel = editor.getScrollingModel();
if (visibleAreaListener != null) {
scrollingModel.addVisibleAreaListener(visibleAreaListener);
scrollingModel.addVisibleAreaListener(myVisibleAreaListener);
}
myFontSizeSynchronizer.synchronize(editor);
source.addDisposable(new Disposable() {
public void dispose() {
myFontSizeSynchronizer.stopSynchronize(editor);
}
});
source.addDisposable(new Disposable() {
public void dispose() {
if (visibleAreaListener != null) {
scrollingModel.removeVisibleAreaListener(visibleAreaListener);
scrollingModel.removeVisibleAreaListener(myVisibleAreaListener);
}
editor.getContentComponent().removeMouseListener(mouseListener);
}
});
}
use of com.intellij.openapi.editor.event.VisibleAreaListener 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