use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class InjectedCaret method setSelection.
@Override
public void setSelection(int startOffset, int endOffset, boolean updateSystemSelection) {
TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
myDelegate.setSelection(hostRange.getStartOffset(), hostRange.getEndOffset(), updateSystemSelection);
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class InjectedCaret method setSelection.
@Override
public void setSelection(@Nullable VisualPosition startPosition, int startOffset, @Nullable VisualPosition endPosition, int endOffset, boolean updateSystemSelection) {
TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
myDelegate.setSelection(startPosition, hostRange.getStartOffset(), endPosition, hostRange.getEndOffset(), updateSystemSelection);
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class EditorMarkupModelImpl method offsetsToYPositions.
@NotNull
private ProperTextRange offsetsToYPositions(int start, int end) {
if (!dimensionsAreValid) {
recalcEditorDimensions();
}
Document document = myEditor.getDocument();
int startLineNumber = end == -1 ? 0 : offsetToLine(start, document);
int startY;
int lineCount;
int editorTargetHeight = Math.max(0, myEditorTargetHeight);
if (myEditorSourceHeight < editorTargetHeight) {
lineCount = 0;
startY = myEditorScrollbarTop + startLineNumber * myEditor.getLineHeight();
} else {
lineCount = myEditorSourceHeight / myEditor.getLineHeight();
startY = myEditorScrollbarTop + (int) ((float) startLineNumber / lineCount * editorTargetHeight);
}
int endY;
int endLineNumber = offsetToLine(end, document);
if (end == -1 || start == -1) {
endY = Math.min(myEditorSourceHeight, editorTargetHeight);
} else if (start == end || offsetToLine(start, document) == endLineNumber) {
// both offsets are on the same line, no need to recalc Y position
endY = startY;
} else if (myEditorSourceHeight < editorTargetHeight) {
endY = myEditorScrollbarTop + endLineNumber * myEditor.getLineHeight();
} else {
endY = myEditorScrollbarTop + (int) ((float) endLineNumber / lineCount * editorTargetHeight);
}
if (endY < startY)
endY = startY;
return new ProperTextRange(startY, endY);
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class EditorMarkupModelImpl method markDirtied.
private void markDirtied(@NotNull ProperTextRange yPositions) {
if (myDirtyYPositions != WHOLE_DOCUMENT) {
int start = Math.max(0, yPositions.getStartOffset() - myEditor.getLineHeight());
int end = myEditorScrollbarTop + myEditorTargetHeight == 0 ? yPositions.getEndOffset() + myEditor.getLineHeight() : Math.min(myEditorScrollbarTop + myEditorTargetHeight, yPositions.getEndOffset() + myEditor.getLineHeight());
ProperTextRange adj = new ProperTextRange(start, Math.max(end, start));
myDirtyYPositions = myDirtyYPositions == null ? adj : myDirtyYPositions.union(adj);
}
myEditorScrollbarTop = 0;
myEditorSourceHeight = 0;
myEditorTargetHeight = 0;
dimensionsAreValid = false;
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class EditorMarkupModelImpl method showToolTipByMouseMove.
private boolean showToolTipByMouseMove(@NotNull final MouseEvent e) {
if (myEditor.getVisibleLineCount() == 0)
return false;
MouseEvent me = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), 0, e.getY() + 1, e.getClickCount(), e.isPopupTrigger());
final int visualLine = getVisualLineByEvent(e);
myLastVisualLine = visualLine;
Rectangle area = myEditor.getScrollingModel().getVisibleArea();
int visualY = myEditor.getLineHeight() * visualLine;
boolean isVisible = area.contains(area.x, visualY) && myWheelAccumulator == 0;
if (UIUtil.uiParents(myEditor.getComponent(), false).filter(EditorWindowHolder.class).isEmpty() || isVisible || !UISettings.getInstance().getShowEditorToolTip()) {
final Set<RangeHighlighter> highlighters = new THashSet<>();
getNearestHighlighters(this, me.getY(), highlighters);
getNearestHighlighters(((EditorEx) getEditor()).getFilteredDocumentMarkupModel(), me.getY(), highlighters);
if (highlighters.isEmpty())
return false;
int y = e.getY();
RangeHighlighter nearest = getNearestRangeHighlighter(e);
if (nearest != null) {
ProperTextRange range = offsetsToYPositions(nearest.getStartOffset(), nearest.getEndOffset());
int eachStartY = range.getStartOffset();
int eachEndY = range.getEndOffset();
y = eachStartY + (eachEndY - eachStartY) / 2;
}
me = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), me.getX(), y + 1, e.getClickCount(), e.isPopupTrigger());
TooltipRenderer bigRenderer = myTooltipRendererProvider.calcTooltipRenderer(highlighters);
if (bigRenderer != null) {
showTooltip(me, bigRenderer, createHint(me));
return true;
}
return false;
} else {
float rowRatio = (float) visualLine / (myEditor.getVisibleLineCount() - 1);
int y = myRowAdjuster != 0 ? (int) (rowRatio * myEditor.getVerticalScrollBar().getHeight()) : me.getY();
me = new MouseEvent(me.getComponent(), me.getID(), me.getWhen(), me.getModifiers(), me.getX(), y, me.getClickCount(), me.isPopupTrigger());
final List<RangeHighlighterEx> highlighters = new ArrayList<>();
collectRangeHighlighters(this, visualLine, highlighters);
collectRangeHighlighters(myEditor.getFilteredDocumentMarkupModel(), visualLine, highlighters);
myEditorFragmentRenderer.update(visualLine, highlighters, me.isAltDown());
myEditorFragmentRenderer.show(myEditor, me.getPoint(), true, ERROR_STRIPE_TOOLTIP_GROUP, createHint(me));
return true;
}
}
Aggregations