当前位置: 首页>>代码示例>>Java>>正文


Java LogicalPosition类代码示例

本文整理汇总了Java中com.intellij.openapi.editor.LogicalPosition的典型用法代码示例。如果您正苦于以下问题:Java LogicalPosition类的具体用法?Java LogicalPosition怎么用?Java LogicalPosition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LogicalPosition类属于com.intellij.openapi.editor包,在下文中一共展示了LogicalPosition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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++;
    }
}
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:27,代码来源:MerlinQueryTypesTask.java

示例2: selectionChanged

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:XVariablesViewBase.java

示例3: beforeMove

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:DeclarationMover.java

示例4: testNavigationInPlatformXml2

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AndroidValueResourcesTest.java

示例5: navigate

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavadocHelper.java

示例6: checkOffsetConversions

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:EditorRtlTest.java

示例7: getAnswerPlaceholder

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:TaskFile.java

示例8: syncVerticalScroll

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:SyncScrollSupport.java

示例9: doTestNavigationToResource

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AndroidSdkSourcesBrowsingTest.java

示例10: doApplyInformationToEditor

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ShowIntentionsPass.java

示例11: getEditorLines

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ChangesFragmentedDiffPanel.java

示例12: setSelected

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:AbstractToggleUseSoftWrapsAction.java

示例13: mouseClicked

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
@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;
   }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:StudyEditorFactoryListener.java

示例14: init

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:LogicalToOffsetCalculationStrategy.java

示例15: deleteToTargetPosition

import com.intellij.openapi.editor.LogicalPosition; //导入依赖的package包/类
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));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:BackspaceHandler.java


注:本文中的com.intellij.openapi.editor.LogicalPosition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。