Java Code Examples for com.intellij.openapi.editor.Editor#xyToLogicalPosition()
The following examples show how to use
com.intellij.openapi.editor.Editor#xyToLogicalPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractToggleUseSoftWrapsAction.java From consulo with Apache License 2.0 | 6 votes |
public static void toggleSoftWraps(@Nonnull 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(); }
Example 2
Source File: BookmarkManager.java From consulo with Apache License 2.0 | 6 votes |
@Override public void mouseClicked(final EditorMouseEvent e) { if (e.getArea() != EditorMouseEventArea.LINE_MARKERS_AREA) return; if (e.getMouseEvent().isPopupTrigger()) return; if ((e.getMouseEvent().getModifiers() & (SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)) == 0) return; Editor editor = e.getEditor(); int line = editor.xyToLogicalPosition(new Point(e.getMouseEvent().getX(), e.getMouseEvent().getY())).line; if (line < 0) return; Document document = editor.getDocument(); Bookmark bookmark = findEditorBookmark(document, line); if (bookmark == null) { addEditorBookmark(editor, line); } else { removeBookmark(bookmark); } e.consume(); }
Example 3
Source File: EditorUtils.java From KJump with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull public static TextRange getVisibleRangeOffset(@NotNull Editor editor) { ScrollingModel scrollingModel = editor.getScrollingModel(); Rectangle visibleArea = scrollingModel.getVisibleArea(); LogicalPosition startLog = editor.xyToLogicalPosition(new Point(0, visibleArea.y)); LogicalPosition lastLog = editor.xyToLogicalPosition(new Point(0, visibleArea.y + visibleArea.height)); int startOff = editor.logicalPositionToOffset(startLog); int endOff = editor.logicalPositionToOffset(new LogicalPosition(lastLog.line + 1, lastLog.column)); return new TextRange(startOff, endOff); }
Example 4
Source File: EditorUtils.java From emacsIDEAs with Apache License 2.0 | 5 votes |
public static TextRange getVisibleTextRange(Editor editor) { Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); LogicalPosition startLogicalPosition = editor.xyToLogicalPosition(visibleArea.getLocation()); Double endVisualX = visibleArea.getX() + visibleArea.getWidth(); Double endVisualY = visibleArea.getY() + visibleArea.getHeight(); LogicalPosition endLogicalPosition = editor.xyToLogicalPosition(new Point(endVisualX.intValue(), endVisualY.intValue())); return new TextRange(editor.logicalPositionToOffset(startLogicalPosition), editor.logicalPositionToOffset(endLogicalPosition)); }
Example 5
Source File: EditorAPI.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Returns the logical line range of the given visible rectangle for the given editor. * * @param editor the editor to get the viewport line range for * @param visibleAreaRectangle the visible rectangle to get the line range for * @return the logical line range of the local viewport for the given editor * @see LogicalPosition */ public static LineRange getLocalViewPortRange( @NotNull Editor editor, @NotNull Rectangle visibleAreaRectangle) { int basePos = visibleAreaRectangle.y; int endPos = visibleAreaRectangle.y + visibleAreaRectangle.height; int currentViewportStartLine = editor.xyToLogicalPosition(new Point(0, basePos)).line; int currentViewportEndLine = editor.xyToLogicalPosition(new Point(0, endPos)).line; return new LineRange( currentViewportStartLine, currentViewportEndLine - currentViewportStartLine); }
Example 6
Source File: DiffDividerDrawUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static Interval getVisibleInterval(Editor editor) { Rectangle area = editor.getScrollingModel().getVisibleArea(); LogicalPosition position1 = editor.xyToLogicalPosition(new Point(0, area.y)); LogicalPosition position2 = editor.xyToLogicalPosition(new Point(0, area.y + area.height)); return new Interval(position1.line, position2.line); }
Example 7
Source File: MergeSearchHelper.java From consulo with Apache License 2.0 | 5 votes |
public static Change findChangeAt(EditorMouseEvent e, MergePanel2 mergePanel, int index) { if (mergePanel.getMergeList() == null) return null; Editor editor = e.getEditor(); LOG.assertTrue(editor == mergePanel.getEditor(index)); LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint()); int offset = editor.logicalPositionToOffset(logicalPosition); return forMergeList(mergePanel.getMergeList(), index).findChangeAt(offset); }
Example 8
Source File: SyncScrollSupport.java From consulo with Apache License 2.0 | 5 votes |
private static void syncVerticalScroll(@Nonnull ScrollingContext context, @Nonnull Rectangle newRectangle, @Nonnull Rectangle oldRectangle) { if (newRectangle.y == oldRectangle.y) return; EditingSides sidesContainer = context.getSidesContainer(); FragmentSide masterSide = context.getMasterSide(); FragmentSide masterDiffSide = context.getMasterDiffSide(); Editor master = sidesContainer.getEditor(masterSide); Editor slave = sidesContainer.getEditor(masterSide.otherSide()); if (master == null || slave == null) return; int masterVerticalScrollOffset = master.getScrollingModel().getVerticalScrollOffset(); int slaveVerticalScrollOffset = slave.getScrollingModel().getVerticalScrollOffset(); Rectangle viewRect = master.getScrollingModel().getVisibleArea(); int middleY = viewRect.height / 3; if (master.getDocument().getTextLength() == 0) return; LogicalPosition masterPos = master.xyToLogicalPosition(new Point(viewRect.x, masterVerticalScrollOffset + middleY)); int masterCenterLine = masterPos.line; int scrollToLine = sidesContainer.getLineBlocks().transform(masterDiffSide, masterCenterLine); int offset; if (scrollToLine < 0) { offset = slaveVerticalScrollOffset + newRectangle.y - oldRectangle.y; } else { int correction = (masterVerticalScrollOffset + middleY) % master.getLineHeight(); Point point = slave.logicalPositionToXY(new LogicalPosition(scrollToLine, masterPos.column)); offset = point.y - middleY + correction; } int deltaHeaderOffset = getHeaderOffset(slave) - getHeaderOffset(master); doScrollVertically(slave.getScrollingModel(), offset + deltaHeaderOffset); }
Example 9
Source File: DaemonListeners.java From consulo with Apache License 2.0 | 5 votes |
@Override public void mouseMoved(@Nonnull EditorMouseEvent e) { if (Registry.is("ide.disable.editor.tooltips") || Registry.is("editor.new.mouse.hover.popups")) { return; } Editor editor = e.getEditor(); if (myProject != editor.getProject()) return; if (EditorMouseHoverPopupControl.arePopupsDisabled(editor)) return; boolean shown = false; try { if (e.getArea() == EditorMouseEventArea.EDITING_AREA && !UIUtil.isControlKeyDown(e.getMouseEvent()) && DocumentationManager.getInstance(myProject).getDocInfoHint() == null && EditorUtil.isPointOverText(editor, e.getMouseEvent().getPoint())) { LogicalPosition logical = editor.xyToLogicalPosition(e.getMouseEvent().getPoint()); int offset = editor.logicalPositionToOffset(logical); HighlightInfo info = myDaemonCodeAnalyzer.findHighlightByOffset(editor.getDocument(), offset, false); if (info == null || info.getDescription() == null || info.getHighlighter() != null && FoldingUtil.isHighlighterFolded(editor, info.getHighlighter())) { IdeTooltipManager.getInstance().hideCurrent(e.getMouseEvent()); return; } DaemonTooltipUtil.showInfoTooltip(info, editor, offset); shown = true; } } finally { if (!shown && !TooltipController.getInstance().shouldSurvive(e.getMouseEvent())) { DaemonTooltipUtil.cancelTooltips(); } } }
Example 10
Source File: VisibleHighlightingPassFactory.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static ProperTextRange calculateVisibleRange(@Nonnull Editor editor) { Rectangle rect = editor.getScrollingModel().getVisibleArea(); LogicalPosition startPosition = editor.xyToLogicalPosition(new Point(rect.x, rect.y)); int visibleStart = editor.logicalPositionToOffset(startPosition); LogicalPosition endPosition = editor.xyToLogicalPosition(new Point(rect.x + rect.width, rect.y + rect.height)); int visibleEnd = editor.logicalPositionToOffset(new LogicalPosition(endPosition.line + 1, 0)); return new ProperTextRange(visibleStart, Math.max(visibleEnd, visibleStart)); }
Example 11
Source File: MyActionUtils.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int getMouseOffset(MouseEvent mouseEvent, Editor editor) { Point point=new Point(mouseEvent.getPoint()); LogicalPosition pos=editor.xyToLogicalPosition(point); return editor.logicalPositionToOffset(pos); }
Example 12
Source File: MyActionUtils.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int getMouseOffset(Editor editor) { Point mousePosition = editor.getContentComponent().getMousePosition(); LogicalPosition pos=editor.xyToLogicalPosition(mousePosition); int offset = editor.logicalPositionToOffset(pos); return offset; }
Example 13
Source File: TestRuleAction.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** Only show if selection is a grammar and in a rule */ @Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); presentation.setText("Test ANTLR Rule"); // default text VirtualFile grammarFile = MyActionUtils.getGrammarFileFromEvent(e); if ( grammarFile==null ) { // we clicked somewhere outside text or non grammar file presentation.setEnabled(false); presentation.setVisible(false); return; } ParserRuleRefNode r = null; InputEvent inputEvent = e.getInputEvent(); if ( inputEvent instanceof MouseEvent ) { // this seems to be after update() called 2x and we have selected the action r = MyActionUtils.getParserRuleSurroundingRef(e); } else { // If editor component, mouse event not happened yet to update caret so must ask for mouse position Editor editor = e.getData(PlatformDataKeys.EDITOR); if ( editor!=null ) { Point mousePosition = editor.getContentComponent().getMousePosition(); if ( mousePosition!=null ) { LogicalPosition pos = editor.xyToLogicalPosition(mousePosition); int offset = editor.logicalPositionToOffset(pos); PsiFile file = e.getData(LangDataKeys.PSI_FILE); if ( file!=null ) { PsiElement el = file.findElementAt(offset); if ( el!=null ) { r = MyActionUtils.getParserRuleSurroundingRef(el); } } } } if ( r==null ) { r = MyActionUtils.getParserRuleSurroundingRef(e); } } if ( r==null ) { presentation.setEnabled(false); return; } presentation.setVisible(true); String ruleName = r.getText(); if ( Character.isLowerCase(ruleName.charAt(0)) ) { presentation.setEnabled(true); presentation.setText("Test Rule "+ruleName); } else { presentation.setEnabled(false); } }
Example 14
Source File: DividerPolygon.java From consulo with Apache License 2.0 | 4 votes |
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); }