use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class PrevNextDifferenceIterableBase method canGoNext.
@Override
public boolean canGoNext() {
List<? extends T> changes = getChanges();
if (changes.isEmpty())
return false;
EditorEx editor = getEditor();
int line = editor.getCaretModel().getLogicalPosition().line;
if (line == editor.getDocument().getLineCount() - 1)
return false;
T lastChange = changes.get(changes.size() - 1);
if (getStartLine(lastChange) <= line)
return false;
return true;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class SyncScrollSupport method getTargetOffsets.
@NotNull
private static int[] getTargetOffsets(@NotNull Editor[] editors, int[] startLines, int[] endLines, int preferredTopShift) {
int count = editors.length;
assert startLines.length == count;
assert endLines.length == count;
int[] topOffsets = new int[count];
int[] bottomOffsets = new int[count];
int[] rangeHeights = new int[count];
int[] gapLines = new int[count];
int[] editorHeights = new int[count];
int[] maximumOffsets = new int[count];
int[] topShifts = new int[count];
for (int i = 0; i < count; i++) {
topOffsets[i] = editors[i].logicalPositionToXY(new LogicalPosition(startLines[i], 0)).y;
bottomOffsets[i] = editors[i].logicalPositionToXY(new LogicalPosition(endLines[i] + 1, 0)).y;
rangeHeights[i] = bottomOffsets[i] - topOffsets[i];
gapLines[i] = 2 * editors[i].getLineHeight();
editorHeights[i] = editors[i].getScrollingModel().getVisibleArea().height;
maximumOffsets[i] = ((EditorEx) editors[i]).getScrollPane().getVerticalScrollBar().getMaximum() - editorHeights[i];
// 'shift' here - distance between editor's top and first line of range
// make whole range visible. If possible, locate it at 'center' (1/3 of height) (or at 'preferredTopShift' if it was specified)
// If can't show whole range - show as much as we can
boolean canShow = 2 * gapLines[i] + rangeHeights[i] <= editorHeights[i];
int shift = preferredTopShift != -1 ? preferredTopShift : editorHeights[i] / 3;
topShifts[i] = canShow ? Math.min(editorHeights[i] - gapLines[i] - rangeHeights[i], shift) : gapLines[i];
}
int topShift = ArrayUtil.min(topShifts);
// check if we're at the top of file
topShift = Math.min(topShift, ArrayUtil.min(topOffsets));
int[] offsets = new int[count];
boolean haveEnoughSpace = true;
for (int i = 0; i < count; i++) {
offsets[i] = topOffsets[i] - topShift;
haveEnoughSpace &= maximumOffsets[i] > offsets[i];
}
if (haveEnoughSpace)
return offsets;
// One of the ranges is at end of file - we can't scroll where we want to.
topShift = 0;
for (int i = 0; i < count; i++) {
topShift = Math.max(topOffsets[i] - maximumOffsets[i], topShift);
}
for (int i = 0; i < count; i++) {
// Try to show as much of range as we can (even if it breaks alignment)
offsets[i] = topOffsets[i] - topShift + Math.max(topShift + rangeHeights[i] + gapLines[i] - editorHeights[i], 0);
// always show top of the range
offsets[i] = Math.min(offsets[i], topOffsets[i] - gapLines[i]);
}
return offsets;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class DiffUtil method createEditor.
@NotNull
public static EditorEx createEditor(@NotNull Document document, @Nullable Project project, boolean isViewer, boolean enableFolding) {
EditorFactory factory = EditorFactory.getInstance();
EditorEx editor = (EditorEx) (isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));
editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
editor.getSettings().setShowIntentionBulb(false);
((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
editor.getGutterComponentEx().setShowDefaultGutterPopup(false);
if (enableFolding) {
setFoldingModelSupport(editor);
} else {
editor.getSettings().setFoldingOutlineShown(false);
editor.getFoldingModel().setFoldingEnabled(false);
}
UIUtil.removeScrollBorder(editor.getComponent());
return editor;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class LanguageConsoleImpl method installEditorFactoryListener.
private void installEditorFactoryListener() {
FileEditorManagerListener fileEditorListener = new FileEditorManagerListener() {
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (myConsoleEditor == null || !Comparing.equal(file, getVirtualFile())) {
return;
}
Editor selectedTextEditor = source.getSelectedTextEditor();
for (FileEditor fileEditor : source.getAllEditors(file)) {
if (!(fileEditor instanceof TextEditor)) {
continue;
}
final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor();
editor.addFocusListener(myFocusListener);
if (selectedTextEditor == editor) {
// already focused
myCurrentEditor = editor;
}
EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent());
}
}
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (!Comparing.equal(file, getVirtualFile())) {
return;
}
if (!Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) {
if (myCurrentEditor != null && myCurrentEditor.isDisposed()) {
myCurrentEditor = null;
}
}
}
};
myBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener);
FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
if (editorManager.isFileOpen(getVirtualFile())) {
fileEditorListener.fileOpened(editorManager, getVirtualFile());
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class LightAdvHighlightingTest method testAnnotatorWorksWithFileLevel.
public void testAnnotatorWorksWithFileLevel() {
Annotator annotator = new MyTopFileAnnotator();
Language java = StdFileTypes.JAVA.getLanguage();
LanguageAnnotators.INSTANCE.addExplicitExtension(java, annotator);
try {
List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
assertTrue(list.toString(), list.contains(annotator));
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
// whole file fit onscreen
((EditorEx) getEditor()).getScrollPane().getViewport().setSize(new Dimension(1000, 1000));
doHighlighting();
List<HighlightInfo> fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
HighlightInfo info = assertOneElement(fileLevel);
assertEquals("top level", info.getDescription());
type("\n\n");
doHighlighting();
fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
info = assertOneElement(fileLevel);
assertEquals("top level", info.getDescription());
//disable top level annotation
type("//xxx");
List<HighlightInfo> warnings = doHighlighting(HighlightSeverity.WARNING);
assertEmpty(warnings);
fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
assertEmpty(fileLevel);
} finally {
LanguageAnnotators.INSTANCE.removeExplicitExtension(java, annotator);
}
List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
assertFalse(list.toString(), list.contains(annotator));
}
Aggregations