use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class AbstractToggleUseSoftWrapsAction method toggleSoftWraps.
public static void toggleSoftWraps(@NotNull Editor editor, @Nullable SoftWrapAppliancePlaces places, boolean state) {
Point point = editor.getScrollingModel().getVisibleArea().getLocation();
LogicalPosition anchorPosition = editor.xyToLogicalPosition(point);
int intraLineShift = point.y - editor.logicalPositionToXY(anchorPosition).y;
if (places != null) {
EditorSettingsExternalizable.getInstance().setUseSoftWraps(state, places);
EditorFactory.getInstance().refreshAllEditors();
}
if (editor.getSettings().isUseSoftWraps() != state) {
editor.getSettings().setUseSoftWraps(state);
}
editor.getScrollingModel().disableAnimation();
editor.getScrollingModel().scrollVertically(editor.logicalPositionToXY(anchorPosition).y + intraLineShift);
editor.getScrollingModel().enableAnimation();
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class DividerPolygon method getVisibleInterval.
static Interval getVisibleInterval(Editor editor) {
int offset = editor.getScrollingModel().getVerticalScrollOffset();
LogicalPosition logicalPosition = editor.xyToLogicalPosition(new Point(0, offset));
int line = logicalPosition.line;
return new Interval(line, editor.getComponent().getHeight() / editor.getLineHeight() + 1);
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-plugins by JetBrains.
the class DartStatementMover method checkAvailable.
@Override
public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) {
if (!(file instanceof DartFile))
return false;
if (!super.checkAvailable(editor, file, info, down))
return false;
LineRange range = expandLineRangeToCoverPsiElements(info.toMove, editor, file);
if (range == null)
return false;
info.toMove = range;
final int startOffset = editor.logicalPositionToOffset(new LogicalPosition(range.startLine, 0));
final int endOffset = editor.logicalPositionToOffset(new LogicalPosition(range.endLine, 0));
PsiElement[] statements = DartRefactoringUtil.findListExpressionInRange(file, startOffset, endOffset);
if (statements.length == 1) {
// Disallow component mover
info.toMove2 = null;
// Require trailing comma
return true;
}
if (statements.length == 0) {
statements = DartRefactoringUtil.findStatementsInRange(file, startOffset, endOffset);
}
if (statements.length == 0)
return false;
range.firstElement = statements[0];
range.lastElement = statements[statements.length - 1];
info.indentTarget = true;
if (!checkMovingInsideOutside(file, editor, info, down)) {
info.toMove2 = null;
}
return true;
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class BraceHighlightingHandler method showScopeHint.
private void showScopeHint(final int lbraceStart, final int lbraceEnd) {
LogicalPosition bracePosition = myEditor.offsetToLogicalPosition(lbraceStart);
Point braceLocation = myEditor.logicalPositionToXY(bracePosition);
final int y = braceLocation.y;
myAlarm.addRequest(() -> {
if (myProject.isDisposed())
return;
PsiDocumentManager.getInstance(myProject).performLaterWhenAllCommitted(() -> {
if (!myEditor.getComponent().isShowing())
return;
Rectangle viewRect = myEditor.getScrollingModel().getVisibleArea();
if (y < viewRect.y) {
int start = lbraceStart;
if (!(myPsiFile instanceof PsiPlainTextFile) && myPsiFile.isValid()) {
start = BraceMatchingUtil.getBraceMatcher(getFileTypeByOffset(lbraceStart), PsiUtilCore.getLanguageAtOffset(myPsiFile, lbraceStart)).getCodeConstructStart(myPsiFile, lbraceStart);
}
TextRange range = new TextRange(start, lbraceEnd);
int line1 = myDocument.getLineNumber(range.getStartOffset());
int line2 = myDocument.getLineNumber(range.getEndOffset());
line1 = Math.max(line1, line2 - 5);
range = new TextRange(myDocument.getLineStartOffset(line1), range.getEndOffset());
LightweightHint hint = EditorFragmentComponent.showEditorFragmentHint(myEditor, range, true, true);
myEditor.putUserData(HINT_IN_EDITOR_KEY, hint);
}
});
}, 300, ModalityState.stateForComponent(myEditor.getComponent()));
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class LookupUi method calculatePosition.
// in layered pane coordinate system.
Rectangle calculatePosition() {
final JComponent lookupComponent = myLookup.getComponent();
Dimension dim = lookupComponent.getPreferredSize();
int lookupStart = myLookup.getLookupStart();
Editor editor = myLookup.getTopLevelEditor();
if (lookupStart < 0 || lookupStart > editor.getDocument().getTextLength()) {
LOG.error(lookupStart + "; offset=" + editor.getCaretModel().getOffset() + "; element=" + myLookup.getPsiElement());
}
LogicalPosition pos = editor.offsetToLogicalPosition(lookupStart);
Point location = editor.logicalPositionToXY(pos);
location.y += editor.getLineHeight();
location.x -= myLookup.myCellRenderer.getTextIndent();
// extra check for other borders
final Window window = UIUtil.getWindow(lookupComponent);
if (window != null) {
final Point point = SwingUtilities.convertPoint(lookupComponent, 0, 0, window);
location.x -= point.x;
}
SwingUtilities.convertPointToScreen(location, editor.getContentComponent());
final Rectangle screenRectangle = ScreenUtil.getScreenRectangle(location);
if (!isPositionedAboveCaret()) {
int shiftLow = screenRectangle.height - (location.y + dim.height);
myPositionedAbove = shiftLow < 0 && shiftLow < location.y - dim.height && location.y >= dim.height;
}
if (isPositionedAboveCaret()) {
location.y -= dim.height + editor.getLineHeight();
if (pos.line == 0) {
location.y += 1;
//otherwise the lookup won't intersect with the editor and every editor's resize (e.g. after typing in console) will close the lookup
}
}
if (!screenRectangle.contains(location)) {
location = ScreenUtil.findNearestPointOnBorder(screenRectangle, location);
}
final JRootPane rootPane = editor.getComponent().getRootPane();
if (rootPane == null) {
LOG.error("editor.disposed=" + editor.isDisposed() + "; lookup.disposed=" + myLookup.isLookupDisposed() + "; editorShowing=" + editor.getContentComponent().isShowing());
}
Rectangle candidate = new Rectangle(location, dim);
ScreenUtil.cropRectangleToFitTheScreen(candidate);
SwingUtilities.convertPointFromScreen(location, rootPane.getLayeredPane());
myMaximumHeight = candidate.height;
return new Rectangle(location.x, location.y, dim.width, candidate.height);
}
Aggregations