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


Java VisualPosition类代码示例

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


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

示例1: getVisibleBestPopupLocation

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
@Nullable
private static Point getVisibleBestPopupLocation(@NotNull Editor editor) {
  VisualPosition visualPosition = editor.getUserData(ANCHOR_POPUP_POSITION);

  if (visualPosition == null) {
    CaretModel caretModel = editor.getCaretModel();
    if (caretModel.isUpToDate()) {
      visualPosition = caretModel.getVisualPosition();
    }
    else {
      visualPosition = editor.offsetToVisualPosition(caretModel.getOffset());
    }
  }

  Point p = editor.visualPositionToXY(new VisualPosition(visualPosition.line + 1, visualPosition.column));

  final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
  return visibleArea.contains(p) ? p : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PopupFactoryImpl.java

示例2: executeWriteAction

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  if (editor.getSelectionModel().hasSelection()) {
    int selStart = editor.getSelectionModel().getSelectionStart();
    int selEnd = editor.getSelectionModel().getSelectionEnd();
    if (selEnd > selStart && DocumentUtil.isAtLineStart(selEnd, editor.getDocument())) {
      selEnd--;
    }
    VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd));
    VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd));
    final Couple<Integer> copiedRange =
      DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd);
    if (copiedRange != null) {
      editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second);
    }
  }
  else {
    VisualPosition caretPos = editor.getCaretModel().getVisualPosition();
    DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), caretPos, caretPos);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DuplicateLinesAction.java

示例3: EditorComponentImpl

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
public EditorComponentImpl(@NotNull EditorImpl editor) {
  myEditor = editor;
  enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.INPUT_METHOD_EVENT_MASK);
  enableInputMethods(true);
  setFocusCycleRoot(true);
  setOpaque(true);

  putClientProperty(Magnificator.CLIENT_PROPERTY_KEY, new Magnificator() {
    @Override
    public Point magnify(double scale, Point at) {
      VisualPosition magnificationPosition = myEditor.xyToVisualPosition(at);
      double currentSize = myEditor.getColorsScheme().getEditorFontSize();
      int defaultFontSize = EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
      myEditor.setFontSize(Math.max((int)(currentSize * scale), defaultFontSize));

      return myEditor.visualPositionToXY(magnificationPosition);
    }
  });
  myApplication = (ApplicationImpl)ApplicationManager.getApplication();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:EditorComponentImpl.java

示例4: isCaretAfterSoftWrap

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
/**
 * Every soft wrap implies that multiple visual positions correspond to the same document offset. We can classify
 * such positions by the following criteria:
 * <pre>
 * <ul>
 *   <li>positions from visual line with soft wrap start;</li>
 *   <li>positions from visual line with soft wrap end;</li>
 * </ul>
 * </pre>
 * <p/>
 * This method allows to answer if caret offset of the given editor points to soft wrap and visual caret position
 * belongs to the visual line where soft wrap end is located.
 *
 * @param editor    target editor
 * @return          <code>true</code> if caret offset of the given editor points to visual position that belongs to
 *                  visual line where soft wrap end is located
 */
public static boolean isCaretAfterSoftWrap(CaretImpl caret) {
  if (!caret.isUpToDate()) {
    return false;
  }
  EditorImpl editor = caret.getEditor();
  SoftWrapModel softWrapModel = editor.getSoftWrapModel();
  int offset = caret.getOffset();
  SoftWrap softWrap = softWrapModel.getSoftWrap(offset);
  if (softWrap == null) {
    return false;
  }

  if (editor.myUseNewRendering) {
    VisualPosition afterWrapPosition = editor.offsetToVisualPosition(offset, false, false);
    VisualPosition caretPosition = caret.getVisualPosition();
    return caretPosition.line == afterWrapPosition.line && caretPosition.column <= afterWrapPosition.column;
  }
  else {
    return editor.offsetToVisualLine(offset) == caret.getVisualPosition().line;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:SoftWrapHelper.java

示例5: testMoveCaretFromVirtualSpaceToRealOffset

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
public void testMoveCaretFromVirtualSpaceToRealOffset() throws IOException {
  boolean virtualSpacesBefore = EditorSettingsExternalizable.getInstance().isVirtualSpace();
  EditorSettingsExternalizable.getInstance().setVirtualSpace(true);

  try {
    doTestDeleteToStart("\n a a \n b b \n", new VisualPosition(1, 10), "\n<caret>\n b b \n", new VisualPosition(1, 0));
    doTestDeleteToStart("\n a a \n b b \n", new VisualPosition(2, 10), "\n a a \n<caret>\n", new VisualPosition(2, 0));
    doTestDeleteToStart("\n a a \n b b \n", new VisualPosition(3, 10), "\n a a \n b b \n<caret>", new VisualPosition(3, 0));

    doTestDeleteToStart("\n a a \n b b \n", new VisualPosition(20, 10), "\n a a \n b b \n<caret>", new VisualPosition(3, 0));

    doTestDeleteToEnd("\n a a \n b b \n", new VisualPosition(1, 10), "\n a a <caret> b b \n", new VisualPosition(1, 5));

    // keep old behavior - not sure if it was intentional or not
    doTestDeleteToEnd("\n a a \n b b \n", new VisualPosition(3, 10), "\n a a \n b b \n<caret>", new VisualPosition(3, 10));
  }
  finally {
    EditorSettingsExternalizable.getInstance().setVirtualSpace(virtualSpacesBefore);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:DeleteToLineStartAndEndActionsTest.java

示例6: doTestDelete

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
private void doTestDelete(boolean toStart,
                          @NotNull String before, @Nullable VisualPosition positionBefore,
                          @NotNull String after, @Nullable VisualPosition positionAfter) throws IOException {
  configureFromFileText(getTestName(false) + ".txt", before);
  if (positionBefore != null) mouse().clickAt(positionBefore.line, positionBefore.column);

  if (toStart) {
    deleteToLineStart();
  }
  else {
    deleteToLineEnd();
  }

  checkResultByText(after);

  if (positionAfter != null) {
    assertEquals(positionAfter, getEditor().getCaretModel().getVisualPosition());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:DeleteToLineStartAndEndActionsTest.java

示例7: checkOffsetConversions

import com.intellij.openapi.editor.VisualPosition; //导入依赖的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

示例8: executeWriteAction

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  Project project = editor.getProject();
  if (project != null && !editor.getSelectionModel().hasSelection()) {
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file != null) {
      VisualPosition caret = editor.getCaretModel().getVisualPosition();
      Pair<LogicalPosition, LogicalPosition> lines = EditorUtil.calcSurroundingRange(editor, caret, caret);
      TextRange toDuplicate = new TextRange(editor.logicalPositionToOffset(lines.first), editor.logicalPositionToOffset(lines.second));

      PsiElement name = findNameIdentifier(editor, file, toDuplicate);
      if (name != null && !name.getTextRange().containsOffset(editor.getCaretModel().getOffset())) {
        editor.getCaretModel().moveToOffset(name.getTextOffset());
      }
    }
  }

  myOriginal.execute(editor, dataContext);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:NamedElementDuplicateHandler.java

示例9: calculateSelectedTextRectangle

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
private void calculateSelectedTextRectangle() {
  SelectionModel selectionModel = myEditor.getSelectionModel();
  int selectionStartOffset = selectionModel.getSelectionStart();
  int selectionEndOffset = selectionModel.getSelectionEnd();

  VisualPosition maxColumnVp = getMaxColumnInsideRange(selectionStartOffset, selectionEndOffset);

  Point maxColumnsPoint = myEditor.visualPositionToXY(maxColumnVp);
  Point selectionStart = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(selectionStartOffset));
  Point selectionEnd = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(selectionEndOffset));

  selectionStart = SwingUtilities.convertPoint(myContentComponent, selectionStart, myEditorComponent);
  selectionEnd = SwingUtilities.convertPoint(myContentComponent, selectionEnd, myEditorComponent);
  maxColumnsPoint = SwingUtilities.convertPoint(myContentComponent, maxColumnsPoint, myEditorComponent);

  mySelectionStartY = selectionStart.y;
  mySelectionEndY = selectionEnd.y;
  myTextRangeMaxColumnX = maxColumnsPoint.x;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ConfigureCodeStyleOnSelectedFragment.java

示例10: afterCreateToStringMethod

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
/**
 * This method is executed just after the <code>toString</code> method is created or updated.
 *
 * @param method   the newly created/updated <code>toString</code> method.
 * @param params   additional parameters stored with key/value in the map.
 * @param template the template to use
 * @throws IncorrectOperationException is thrown by IDEA
 */
private void afterCreateToStringMethod(PsiMethod method, Map<String, String> params, TemplateResource template) {
  PsiFile containingFile = clazz.getContainingFile();
  if (containingFile instanceof PsiJavaFile) {
    final PsiJavaFile javaFile = (PsiJavaFile)containingFile;
    if (params.get("autoImportPackages") != null) {
      // keep this for old user templates
      autoImportPackages(javaFile, params.get("autoImportPackages"));
    }
  }
  method = (PsiMethod)JavaCodeStyleManager.getInstance(clazz.getProject()).shortenClassReferences(method);

  // jump to method
  if (!config.isJumpToMethod() || editor == null) {
    return;
  }
  int offset = method.getTextOffset();
  if (offset <= 2) {
    return;
  }
  VisualPosition vp = editor.offsetToVisualPosition(offset);
  if (logger.isDebugEnabled()) logger.debug("Moving/Scrolling caret to " + vp + " (offset=" + offset + ")");
  editor.getCaretModel().moveToVisualPosition(vp);
  editor.getScrollingModel().scrollToCaret(ScrollType.CENTER_DOWN);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:GenerateToStringWorker.java

示例11: getSelectedText

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
private String getSelectedText(SelectionModel selectionModel, Document document) {
    VisualPosition start = selectionModel.getSelectionStartPosition();
    VisualPosition end = selectionModel.getSelectionEndPosition();

    String lines[] = document.getText().split("\n");
    List<String> contentLines = new ArrayList<String>();

    for (int i = start.getLine(); i <= end.getLine(); i++) {
        contentLines.add(lines[i]);
    }

    int diff = contentLines.get(0).length() - contentLines.get(0).trim().length();

    if (diff > 0) {
        for (int i = 0; i < contentLines.size(); i++) {
            contentLines.set(i, this.leftTrim(contentLines.get(i), diff));
        }
    }

    return this.arrayToStringConversion(contentLines);
}
 
开发者ID:RobinMalfait,项目名称:KopyPasta,代码行数:22,代码来源:Generate.java

示例12: getTypeInfo

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
public static String getTypeInfo(Module module, VisualPosition blockStart, VisualPosition blockEnd, VirtualFile projectFile) {
    final String canonicalPath = projectFile.getCanonicalPath();
    if (canonicalPath == null){
        return "canonical path is null";
    }
    final String workDir = ExecUtil.guessWorkDir(module);
    if (ToolKey.GHC_MODI_KEY.getPath(module.getProject()) != null) {
        GhcModi ghcModi = module.getComponent(GhcModi.class);
        if (ghcModi != null) {
            return GhcModi.getFutureType(module.getProject(), ghcModi.type(canonicalPath,
                    blockStart, blockEnd));

        } else {
            return "ghcModi is not configured";
        }
    } else {
        return GhcMod.type(module, workDir, canonicalPath, blockStart, blockEnd);
    }
}
 
开发者ID:carymrobbins,项目名称:intellij-haskforce,代码行数:20,代码来源:TypeInfoUtil.java

示例13: type

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
public Future<String> type(final @NotNull String canonicalPath,
                           @NotNull final VisualPosition startPosition,
                           @NotNull final VisualPosition  stopPosition) {
    return handleGhcModiCall(new GhcModiCallable<String>(){
        @Override
        public String call() throws GhcModiError {
            final String command = "type " + canonicalPath + ' ' + startPosition.line + ' ' + startPosition.column;
            final String stdout = simpleExec(command);
            try {
                return stdout == null ? "Type info not found" : GhcModUtil.handleTypeInfo(startPosition, stopPosition, stdout);
            } catch (GhcModUtil.TypeInfoParseException e) {
                NotificationUtil.displayToolsNotification(
                  NotificationType.ERROR, module.getProject(), "Type Info Error",
                  "There was an error when executing the ghc-modi `type` command:\n\n" + stdout);
                return null;
            }
        }
    });
}
 
开发者ID:carymrobbins,项目名称:intellij-haskforce,代码行数:20,代码来源:GhcModi.java

示例14: generateDoc

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
    int startOffset = element.getTextRange().getStartOffset();
    int endOffset = element.getTextRange().getEndOffset();
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    FileDocumentManager fileDocumentManager= FileDocumentManager.getInstance();
    VirtualFile projectFile = element.getContainingFile().getVirtualFile();
    Document cachedDocument = fileDocumentManager.getCachedDocument(projectFile);
    if (cachedDocument == null) {
        return null;
    }
    int startLineNumber = cachedDocument.getLineNumber(startOffset);
    int endLineNumber = cachedDocument.getLineNumber(endOffset);
    int startColumn = startOffset - cachedDocument.getLineStartOffset(startLineNumber);
    int endColumn = endOffset - cachedDocument.getLineStartOffset(endLineNumber);

    // and also correct them for (0,0) vs (1,1) leftmost coordinate (intellij -> ghc)
    VisualPosition startPosition = TypeInfoUtil.correctFor0BasedVS1Based(new VisualPosition(startLineNumber, startColumn));
    VisualPosition endPosition = TypeInfoUtil.correctFor0BasedVS1Based(new VisualPosition(endLineNumber, endColumn));
    return TypeInfoUtil.getTypeInfo(module,startPosition,endPosition, projectFile);
}
 
开发者ID:carymrobbins,项目名称:intellij-haskforce,代码行数:22,代码来源:HaskellDocumentationProvider.java

示例15: executeWriteAction

import com.intellij.openapi.editor.VisualPosition; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  if (editor.getSelectionModel().hasSelection()) {
    int selStart = editor.getSelectionModel().getSelectionStart();
    int selEnd = editor.getSelectionModel().getSelectionEnd();
    VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd));
    VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd));
    final Pair<Integer,Integer> copiedRange =
      DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd);
    if (copiedRange != null) {
      editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second);
    }
  }
  else {
    VisualPosition caretPos = editor.getCaretModel().getVisualPosition();
    DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), caretPos, caretPos);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:DuplicateLinesAction.java


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