@Override public void run() { MerlinService merlin = ApplicationManager.getApplication().getComponent(MerlinService.class); if (merlin == null) { return; } String filename = m_psiFile.getVirtualFile().getCanonicalPath(); // Update merlin buffer String source = m_psiFile.getText(); int i = 0; for (PsiLet letStatement : m_letStatements) { LogicalPosition position = m_positions.get(i); if (position != null) { List<MerlinType> types = merlin.typeExpression(filename, source, new MerlinPosition(position)); if (!types.isEmpty()) { // System.out.println(letStatement.getLetName().getText() + ": " + types.stream().map(merlinType -> merlinType.type).reduce("", (s, s2) -> s + s2.replaceAll("\n", "").replaceAll("\\s+", "") + ", ")); // Display only the first one, might be wrong !? letStatement.setInferredType(types.get(0).type.replaceAll("\n", "").replaceAll("\\s+", " ")); } } i++; } }
@Override public void selectionChanged(final SelectionEvent e) { if (!Registry.is("debugger.valueTooltipAutoShowOnSelection") || myEditor.getCaretModel().getCaretCount() > 1) { return; } final String text = myEditor.getDocument().getText(e.getNewRange()); if (!StringUtil.isEmpty(text) && !(text.contains("exec(") || text.contains("++") || text.contains("--") || text.contains("="))) { final XDebugSession session = getSession(getTree()); if (session == null) return; XDebuggerEvaluator evaluator = myStackFrame.getEvaluator(); if (evaluator == null) return; TextRange range = e.getNewRange(); ExpressionInfo info = new ExpressionInfo(range); int offset = range.getStartOffset(); LogicalPosition pos = myEditor.offsetToLogicalPosition(offset); Point point = myEditor.logicalPositionToXY(pos); new XValueHint(myProject, myEditor, point, ValueHintType.MOUSE_OVER_HINT, info, evaluator, session).invokeHint(); } }
@Override public void beforeMove(@NotNull final Editor editor, @NotNull final MoveInfo info, final boolean down) { super.beforeMove(editor, info, down); if (myEnumToInsertSemicolonAfter != null) { TreeElement semicolon = Factory.createSingleLeafElement(JavaTokenType.SEMICOLON, ";", 0, 1, null, myEnumToInsertSemicolonAfter.getManager()); try { PsiElement inserted = myEnumToInsertSemicolonAfter.getParent().addAfter(semicolon.getPsi(), myEnumToInsertSemicolonAfter); inserted = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(inserted); final LogicalPosition position = editor.offsetToLogicalPosition(inserted.getTextRange().getEndOffset()); info.toMove2 = new LineRange(position.line + 1, position.line + 1); } catch (IncorrectOperationException e) { LOG.error(e); } finally { myEnumToInsertSemicolonAfter = null; } } }
public void testNavigationInPlatformXml2() throws Exception { final VirtualFile file = LocalFileSystem.getInstance().findFileByPath( getTestSdkPath() + "/platforms/" + getPlatformDir() + "/data/res/values/resources.xml"); myFixture.configureFromExistingVirtualFile(file); myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(19, 17)); PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset()); assertNotNull(targets); assertEquals(1, targets.length); final PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]); assertInstanceOf(targetElement, XmlAttributeValue.class); final XmlAttributeValue targetAttrValue = (XmlAttributeValue)targetElement; assertEquals("Theme", targetAttrValue.getValue()); assertEquals("name", ((XmlAttribute)targetAttrValue.getParent()).getName()); assertEquals("style", ((XmlTag)targetAttrValue.getParent().getParent()).getName()); assertEquals(file, targetElement.getContainingFile().getVirtualFile()); }
/** * Tries to navigate caret at the given editor to the target position inserting missing white spaces if necessary. * * @param position target caret position * @param editor target editor * @param project target project */ @SuppressWarnings("MethodMayBeStatic") public void navigate(@NotNull LogicalPosition position, @NotNull Editor editor, @NotNull final Project project) { final Document document = editor.getDocument(); final CaretModel caretModel = editor.getCaretModel(); final int endLineOffset = document.getLineEndOffset(position.line); final LogicalPosition endLinePosition = editor.offsetToLogicalPosition(endLineOffset); if (endLinePosition.column < position.column && !editor.getSettings().isVirtualSpace() && !editor.isViewer()) { final String toInsert = StringUtil.repeat(" ", position.column - endLinePosition.column); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { document.insertString(endLineOffset, toInsert); PsiDocumentManager.getInstance(project).commitDocument(document); } }); } caretModel.moveToLogicalPosition(position); }
private static void checkOffsetConversions(int offset, LogicalPosition logicalPosition, VisualPosition visualPositionTowardsSmallerOffsets, VisualPosition visualPositionTowardsLargerOffsets, Point xyTowardsSmallerOffsets, Point xyTowardsLargerOffsets) { assertLogicalPositionsEqual("Wrong offset->logicalPosition calculation", logicalPosition, myEditor.offsetToLogicalPosition(offset)); assertVisualPositionsEqual("Wrong beforeOffset->visualPosition calculation", visualPositionTowardsSmallerOffsets, myEditor.offsetToVisualPosition(offset, false, false)); assertVisualPositionsEqual("Wrong afterOffset->visualPosition calculation", visualPositionTowardsLargerOffsets, myEditor.offsetToVisualPosition(offset, true, false)); assertEquals("Wrong afterOffset->visualLine calculation", visualPositionTowardsLargerOffsets.line, ((EditorImpl)myEditor).offsetToVisualLine(offset)); assertEquals("Wrong beforeOffset->xy calculation", xyTowardsSmallerOffsets, ((EditorImpl)myEditor).offsetToXY(offset, false)); assertEquals("Wrong afterOffset->xy calculation", xyTowardsLargerOffsets, ((EditorImpl)myEditor).offsetToXY(offset, true)); }
@Nullable public AnswerPlaceholder getAnswerPlaceholder(@NotNull final Document document, @NotNull final LogicalPosition pos, boolean useAnswerLength) { int line = pos.line; if (line >= document.getLineCount()) { return null; } int column = pos.column; int offset = document.getLineStartOffset(line) + column; for (AnswerPlaceholder placeholder : myAnswerPlaceholders) { if (placeholder.getLine() <= line) { int realStartOffset = placeholder.getRealStartOffset(document); int placeholderLength = useAnswerLength ? placeholder.getPossibleAnswerLength() : placeholder.getLength(); final int length = placeholderLength > 0 ? placeholderLength : 0; int endOffset = realStartOffset + length; if (realStartOffset <= offset && offset <= endOffset) { return placeholder; } } } return null; }
private void syncVerticalScroll(boolean animated) { if (getMaster().getDocument().getTextLength() == 0) return; Rectangle viewRect = getMaster().getScrollingModel().getVisibleArea(); int middleY = viewRect.height / 3; int offset; if (myAnchor == null) { LogicalPosition masterPos = getMaster().xyToLogicalPosition(new Point(viewRect.x, viewRect.y + middleY)); int masterCenterLine = masterPos.line; int convertedCenterLine = convertLine(masterCenterLine); Point point = getSlave().logicalPositionToXY(new LogicalPosition(convertedCenterLine, masterPos.column)); int correction = (viewRect.y + middleY) % getMaster().getLineHeight(); offset = point.y - middleY + correction; } else { double progress = myAnchor.masterStartOffset == myAnchor.masterEndOffset || viewRect.y == myAnchor.masterEndOffset ? 1 : ((double)(viewRect.y - myAnchor.masterStartOffset)) / (myAnchor.masterEndOffset - myAnchor.masterStartOffset); offset = myAnchor.slaveStartOffset + (int)((myAnchor.slaveEndOffset - myAnchor.slaveStartOffset) * progress); } int deltaHeaderOffset = getHeaderOffset(getSlave()) - getHeaderOffset(getMaster()); doScrollVertically(getSlave(), offset + deltaHeaderOffset, animated); }
private void doTestNavigationToResource(LogicalPosition position, int expectedCount, Class<?> aClass) { myFixture.allowTreeAccessForAllFiles(); final String sdkSourcesPath = configureMockSdk(); final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(sdkSourcesPath + "/android/app/Activity.java"); myFixture.configureFromExistingVirtualFile(file); myFixture.getEditor().getCaretModel().moveToLogicalPosition(position); PsiElement[] elements = GotoDeclarationAction.findAllTargetElements( myFixture.getProject(), myFixture.getEditor(), myFixture.getEditor().getCaretModel().getOffset()); assertEquals(expectedCount, elements.length); for (PsiElement element : elements) { assertInstanceOf(LazyValueResourceElementWrapper.computeLazyElement(element), aClass); } }
@Override public void doApplyInformationToEditor() { ApplicationManager.getApplication().assertIsDispatchThread(); if (!ApplicationManager.getApplication().isUnitTestMode() && !myEditor.getContentComponent().hasFocus()) return; // do not show intentions if caret is outside visible area LogicalPosition caretPos = myEditor.getCaretModel().getLogicalPosition(); Rectangle visibleArea = myEditor.getScrollingModel().getVisibleArea(); Point xy = myEditor.logicalPositionToXY(caretPos); if (!visibleArea.contains(xy)) return; TemplateState state = TemplateManagerImpl.getTemplateState(myEditor); if (myShowBulb && (state == null || state.isFinished()) && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(false)) { DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject); codeAnalyzer.setLastIntentionHint(myProject, myFile, myEditor, myIntentionsInfo, myHasToRecreate); } }
private BeforeAfter<Integer> getEditorLines() { final Editor editor = ((DiffPanelImpl) getCurrentPanel()).getEditor1(); Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); final int offset = editor.getScrollingModel().getVerticalScrollOffset(); int leftPixels = offset % editor.getLineHeight(); final Point start = visibleArea.getLocation(); final LogicalPosition startLp = editor.xyToLogicalPosition(start); final Point location = new Point(start.x + visibleArea.width, start.y + visibleArea.height); final LogicalPosition lp = editor.xyToLogicalPosition(location); int curStartLine = startLp.line == editor.getDocument().getLineCount() - 1 ? startLp.line : startLp.line + 1; int cutEndLine = lp.line == 0 ? 0 : lp.line - 1; boolean commonPartOk = leftPixels == 0 || startLp.line == lp.line; return new BeforeAfter<Integer>(commonPartOk && EditorUtil.getSoftWrapCountAfterLineStart(editor, startLp) == 0 ? startLp.line : curStartLine, commonPartOk && EditorUtil.getSoftWrapCountAfterLineStart(editor, lp) == 0 ? lp.line : cutEndLine); }
@Override public void setSelected(AnActionEvent e, boolean state) { final Editor editor = getEditor(e); if (editor == null) { return; } Point point = editor.getScrollingModel().getVisibleArea().getLocation(); LogicalPosition anchorPosition = editor.xyToLogicalPosition(point); int intraLineShift = point.y - editor.logicalPositionToXY(anchorPosition).y; if (myGlobal) { EditorSettingsExternalizable.getInstance().setUseSoftWraps(state, myAppliancePlace); } else { editor.getSettings().setUseSoftWraps(state); } if (editor instanceof EditorEx) { ((EditorEx)editor).reinitSettings(); } editor.getScrollingModel().disableAnimation(); editor.getScrollingModel().scrollVertically(editor.logicalPositionToXY(anchorPosition).y + intraLineShift); editor.getScrollingModel().enableAnimation(); }
@Override public void mouseClicked(EditorMouseEvent e) { final Editor editor = e.getEditor(); final Point point = e.getMouseEvent().getPoint(); final LogicalPosition pos = editor.xyToLogicalPosition(point); final AnswerPlaceholder answerPlaceholder = myTaskFile.getAnswerPlaceholder(editor.getDocument(), pos); if (answerPlaceholder != null) { if (myAnswerPlaceholderWithSelection != null && myAnswerPlaceholderWithSelection == answerPlaceholder) { editor.getSelectionModel().removeSelection(); myAnswerPlaceholderWithSelection = null; } else { int startOffset = answerPlaceholder.getRealStartOffset(editor.getDocument()); editor.getSelectionModel().setSelection(startOffset, startOffset + answerPlaceholder.getLength()); myAnswerPlaceholderWithSelection = answerPlaceholder; } } }
void init(LogicalPosition logical) { CacheEntry entry = MappingUtil.getCacheEntryForLogicalPosition(logical, myCache); if (entry == null) { if (logical.line >= myEditor.getDocument().getLineCount()) { setEagerMatch(myEditor.getDocument().getTextLength()); } else { setEagerMatch(Math.min(myEditor.getDocument().getLineStartOffset(logical.line) + logical.column, myEditor.getDocument().getLineEndOffset(logical.line))); } return; } if (entry.endLogicalLine == logical.line && entry.endLogicalColumn <= logical.column) { setEagerMatch(entry.endOffset); return; } reset(); targetPosition = logical; setTargetEntry(entry, true); }
public static void deleteToTargetPosition(@NotNull Editor editor, @NotNull LogicalPosition pos) { LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition(); if (logicalPosition.line != pos.line) { LOGGER.error("Unexpected caret position: " + logicalPosition + ", target indent position: " + pos); return; } if (pos.column < logicalPosition.column) { int targetOffset = editor.logicalPositionToOffset(pos); int offset = editor.getCaretModel().getOffset(); editor.getSelectionModel().setSelection(targetOffset, offset); EditorModificationUtil.deleteSelectedText(editor); } else if (pos.column > logicalPosition.column) { EditorModificationUtil.insertStringAtCaret(editor, StringUtil.repeatSymbol(' ', pos.column - logicalPosition.column)); } }
@NotNull private static Function<PsiLet, LogicalPosition> letExpressionToLogicalPosition(Editor selectedTextEditor) { return letStatement -> { PsiElement letName = letStatement.getNameIdentifier(); if (letName == null) { return null; } int nameOffset = letName.getTextOffset(); return selectedTextEditor.offsetToLogicalPosition(nameOffset); }; }
public static void setLine(Editor editor, int line, int column) { if (editor != null) { try { int startOffset = editor.logicalPositionToOffset(new LogicalPosition(line, column)); editor.getCaretModel().moveToOffset(startOffset); editor.getScrollingModel().scrollToCaret(ScrollType.CENTER); editor.getSelectionModel().setSelection(startOffset, startOffset); } catch (Exception e) { // do nothing } } }
@Override public void mouseClicked(EditorMouseEvent e) { final Editor editor = e.getEditor(); final Point point = e.getMouseEvent().getPoint(); final LogicalPosition pos = editor.xyToLogicalPosition(point); final AnswerPlaceholder answerPlaceholder = myTaskFile.getAnswerPlaceholder(editor.logicalPositionToOffset(pos)); if (answerPlaceholder == null || answerPlaceholder.getSelected()) { return; } final Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(answerPlaceholder, editor.getDocument()); editor.getSelectionModel().setSelection(offsets.getFirst(), offsets.getSecond()); answerPlaceholder.setSelected(true); }
public void testPositionCalculationForMultilineFoldingWithEmptyPlaceholder() throws Exception { initText("line1\n" + "line2\n" + "line3\n" + "line4"); addCollapsedFoldRegion(6, 17, ""); configureSoftWraps(1000); assertEquals(new LogicalPosition(3, 0), myEditor.visualToLogicalPosition(new VisualPosition(2, 0))); }
private void navigate(final Editor editor, boolean select, LogicalPosition pos, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { int offset = editor.logicalPositionToOffset(pos); if (!isBackgroundImportant && editor.offsetToLogicalPosition(offset).column != pos.column) { if (!select) { setCursor(editor, Cursor.TEXT_CURSOR); return; } } if (data != null) { for (HighlightData highlightData : data) { if (highlightDataContainsOffset(highlightData, editor.logicalPositionToOffset(pos))) { if (!select) setCursor(editor, Cursor.HAND_CURSOR); setSelectedItem(highlightData.getHighlightType(), select); return; } } } if (highlighter != null) { HighlighterIterator itr = ((EditorEx)editor).getHighlighter().createIterator(offset); boolean selection = selectItem(select, itr, highlighter); if (!select && selection) { setCursor(editor, Cursor.HAND_CURSOR); } else { setCursor(editor, Cursor.TEXT_CURSOR); } } }
@NotNull public CaretSnapshot restoreColumn() { if (!myCaret.getEditor().getSettings().isUseSoftWraps()) { myCaret.moveToLogicalPosition(new LogicalPosition(myCaret.getLogicalPosition().line, get(COLUMN))); } return this; }
public void testDeleteLine() throws IOException { doTest("class Foo {\n" + "\n" + "\n" + "}", new LogicalPosition(2, 0), "class Foo {\n" + " \n" + "}", new LogicalPosition(1, 4)); }
@Override protected void checkResult(String dataName) throws Exception { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); super.checkResult(dataName); CodeInsightTestData data = (CodeInsightTestData) myTestDataAfter; if (data.getColumnNumber() >= 0) { assertEquals(dataName + ":caretColumn", data.getColumnNumber(), myEditor.getCaretModel().getLogicalPosition().column + 1); } if (data.getLineNumber() >= 0) { assertEquals(dataName + ":caretLine", data.getLineNumber(), myEditor.getCaretModel().getLogicalPosition().line + 1); } int selectionStart = myEditor.getSelectionModel().getSelectionStart(); int selectionEnd = myEditor.getSelectionModel().getSelectionEnd(); LogicalPosition startPosition = myEditor.offsetToLogicalPosition(selectionStart); LogicalPosition endPosition = myEditor.offsetToLogicalPosition(selectionEnd); if (data.getSelectionStartColumnNumber() >= 0) { assertEquals(dataName + ":selectionStartColumn", data.getSelectionStartColumnNumber(), startPosition.column + 1); } if (data.getSelectionStartLineNumber() >= 0) { assertEquals(dataName + ":selectionStartLine", data.getSelectionStartLineNumber(), startPosition.line + 1); } if (data.getSelectionEndColumnNumber() >= 0) { assertEquals(dataName + ":selectionEndColumn", data.getSelectionEndColumnNumber(), endPosition.column + 1); } if (data.getSelectionEndLineNumber() >= 0) { assertEquals(dataName + ":selectionEndLine", data.getSelectionEndLineNumber(), endPosition.line + 1); } }
public void testAfterProperIndent() throws IOException { doTest("class Foo {\n" + " \n" + "}", new LogicalPosition(1, 10), "class Foo {\n" + " \n" + "}", new LogicalPosition(1, 4)); }
public static void highlightPrepareError(PrepareFailedException e, PsiFile file, Editor editor, final Project project) { if (e.getFile() == file) { final TextRange textRange = e.getTextRange(); final HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, null); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset()); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting")); } }
public static ArrayList<RangeHighlighter> previewMatch(Project project, Match match, Editor editor) { final ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); highlightMatch(project, editor, match, highlighters); final TextRange textRange = match.getTextRange(); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset()); expandAllRegionsCoveringRange(project, editor, textRange); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); return highlighters; }
@Nullable @Override protected LogicalPosition[] getCaretPositions() { int index = getSide().getIndex(); int otherIndex = getSide().other().getIndex(); LogicalPosition[] carets = new LogicalPosition[2]; carets[index] = getEditor().getCaretModel().getLogicalPosition(); carets[otherIndex] = new LogicalPosition(0, 0); return carets; }
public void updateContext(@NotNull DiffRequest request) { LogicalPosition[] carets = getCaretPositions(); EditorsVisiblePositions visiblePositions = getVisiblePositions(); request.putUserData(DiffUserDataKeysEx.SCROLL_TO_CHANGE, null); request.putUserData(EditorsVisiblePositions.KEY, visiblePositions); request.putUserData(DiffUserDataKeysEx.EDITORS_CARET_POSITION, carets); }
private static void scrollHighlightInView(final List<HighlightData> highlightDatas, final Editor editor) { boolean needScroll = true; int minOffset = Integer.MAX_VALUE; for(HighlightData data: highlightDatas) { if (isOffsetVisible(editor, data.getStartOffset())) { needScroll = false; break; } minOffset = Math.min(minOffset, data.getStartOffset()); } if (needScroll && minOffset != Integer.MAX_VALUE) { LogicalPosition pos = editor.offsetToLogicalPosition(minOffset); editor.getScrollingModel().scrollTo(pos, ScrollType.MAKE_VISIBLE); } }
@Override public Result preprocessEnter( PsiFile file, Editor editor, Ref<Integer> caretOffset, Ref<Integer> caretAdvance, DataContext dataContext, EditorActionHandler originalHandler) { int offset = caretOffset.get(); if (editor instanceof EditorWindow) { file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file); editor = InjectedLanguageUtil.getTopLevelEditor(editor); offset = editor.getCaretModel().getOffset(); } if (!isApplicable(file, dataContext) || !insertIndent(file, offset)) { return Result.Continue; } int indent = SectionParser.INDENT; editor.getCaretModel().moveToOffset(offset); Document doc = editor.getDocument(); PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc); originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext); LogicalPosition position = editor.getCaretModel().getLogicalPosition(); if (position.column < indent) { String spaces = StringUtil.repeatSymbol(' ', indent - position.column); doc.insertString(editor.getCaretModel().getOffset(), spaces); } editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent)); return Result.Stop; }
public boolean isSame(@Nullable LogicalPosition... caretPosition) { // TODO: allow small fluctuations ? if (caretPosition == null) return true; if (myCaretPosition.length != caretPosition.length) return false; for (int i = 0; i < caretPosition.length; i++) { if (!caretPosition[i].equals(myCaretPosition[i])) return false; } return true; }
@CalledInAwt @NotNull protected LogicalPosition transferPosition(@NotNull Side baseSide, @NotNull LogicalPosition position) { if (mySyncScrollSupport == null) return position; int line = mySyncScrollSupport.getScrollable().transfer(baseSide, position.line); return new LogicalPosition(line, position.column); }
@Nullable @Override protected OpenFileDescriptor getOpenFileDescriptor() { Side side = getCurrentSide(); int offset = getEditor(side).getCaretModel().getOffset(); OpenFileDescriptor descriptor = getContent(side).getOpenFileDescriptor(offset); if (descriptor != null) return descriptor; LogicalPosition otherPosition = transferPosition(side, getEditor(side).getCaretModel().getLogicalPosition()); int otherOffset = getEditor(side.other()).logicalPositionToOffset(otherPosition); return getContent(side.other()).getOpenFileDescriptor(otherOffset); }
@Override protected OpenFileDescriptor getDescriptor(@NotNull Editor editor, int line) { ThreeSide side = getEditorSide(editor); if (side == null) return null; int offset = editor.logicalPositionToOffset(new LogicalPosition(line, 0)); return getContent(side).getOpenFileDescriptor(offset); }
private void addMouseMotionListener(final Editor view, final SyntaxHighlighter highlighter, final HighlightData[] data, final boolean isBackgroundImportant) { view.getContentComponent().addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { LogicalPosition pos = view.xyToLogicalPosition(new Point(e.getX(), e.getY())); navigate(view, false, pos, highlighter, data, isBackgroundImportant); } }); }
/** * @return 1-based column index where tabs are treated as single characters. External tools don't know about IDEA's tab size. */ protected static String getColumnNumber(Editor editor, LogicalPosition pos) { if (EditorUtil.inVirtualSpace(editor, pos)) { return String.valueOf(pos.column + 1); } int offset = editor.logicalPositionToOffset(pos); int lineStart = editor.getDocument().getLineStartOffset(editor.getDocument().getLineNumber(offset)); return String.valueOf(offset - lineStart + 1); }
private void handleInputFocusMovement(LogicalPosition position) { checkModelValidity(); String text = ""; final int offset = editor.logicalPositionToOffset(position); final int length = editor.getDocument().getTextLength(); final CharSequence elements = editor.getDocument().getCharsSequence(); int start = offset-1; int end = -1; while(start >=0 && Character.isJavaIdentifierPart(elements.charAt(start)) && elements.charAt(start)!='$') start--; if (start >=0 && elements.charAt(start)=='$') { end = offset; while(end < length && Character.isJavaIdentifierPart(elements.charAt(end)) && elements.charAt(end)!='$') end++; if (end < length && elements.charAt(end)=='$') { String varname = elements.subSequence(start + 1, end).toString(); Variable foundVar = null; for (final Variable var : variables) { if (var.getName().equals(varname)) { foundVar = var; break; } } if (foundVar!=null) { text = UIUtil.getShortParamString(editor.getUserData(CURRENT_CONFIGURATION_KEY),varname); } } } if (text.length() > 0) { UIUtil.showTooltip(editor, start, end + 1, text); } else { TooltipController.getInstance().cancelTooltips(); } }
@Override public void perform(@NotNull final Project project, final AnActionEvent event) { Editor editor = event.getData(CommonDataKeys.EDITOR); if (editor != null) { LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition(); ValueLookupManager.getInstance(project). showHint(myHandler, editor, editor.logicalPositionToXY(logicalPosition), ValueHintType.MOUSE_CLICK_HINT); } }
/** * @return position of hint in layered pane coordinate system */ public static Point getHintPosition(@NotNull LightweightHint hint, @NotNull Editor editor, @NotNull LogicalPosition pos, @PositionFlags short constraint) { return getHintPosition(hint, editor, pos, pos, constraint); }