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


Java Caret.getSelectionEnd方法代码示例

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


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

示例1: getLanguageInEditor

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
@Nullable
public static Language getLanguageInEditor(@NotNull Caret caret, @NotNull final Project project) {
  Editor editor = caret.getEditor();
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) return null;

  int caretOffset = caret.getOffset();
  int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionEnd() ? caret.getSelectionStart() : caretOffset;
  PsiElement elt = getElementAtOffset(file, mostProbablyCorrectLanguageOffset);
  Language lang = findLanguageFromElement(elt);

  if (caret.hasSelection()) {
    final Language rangeLanguage = evaluateLanguageInRange(caret.getSelectionStart(), caret.getSelectionEnd(), file);
    if (rangeLanguage == null) return file.getLanguage();

    lang = rangeLanguage;
  }

  return narrowLanguage(lang, file.getLanguage());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PsiUtilBase.java

示例2: getPsiFileInEditor

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
@Nullable
public static PsiFile getPsiFileInEditor(@NotNull Caret caret, @NotNull final Project project) {
  Editor editor = caret.getEditor();
  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) return null;

  PsiUtilCore.ensureValid(file);

  final Language language = getLanguageInEditor(caret, project);
  if (language == null) return file;

  if (language == file.getLanguage()) return file;

  int caretOffset = caret.getOffset();
  int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionEnd() ? caret.getSelectionStart() : caretOffset;
  return getPsiFileAtOffset(file, mostProbablyCorrectLanguageOffset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiUtilBase.java

示例3: getFoldRegionsForSelection

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
/**
 * Returns fold regions inside selection, or all regions in editor, if selection doesn't exist or doesn't contain fold regions.
 */
protected List<FoldRegion> getFoldRegionsForSelection(@NotNull Editor editor, @Nullable Caret caret) {
  FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions();
  if (caret == null) {
    caret = editor.getCaretModel().getPrimaryCaret();
  }
  if (caret.hasSelection()) {
    List<FoldRegion> result = new ArrayList<FoldRegion>();
    for (FoldRegion region : allRegions) {
      if (region.getStartOffset() >= caret.getSelectionStart() && region.getEndOffset() <= caret.getSelectionEnd()) {
        result.add(region);
      }
    }
    if (!result.isEmpty()) {
      return result;
    }
  }
  return Arrays.asList(allRegions);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:BaseFoldingHandler.java

示例4: getLanguageAtCurrentPositionInEditor

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
private static Language getLanguageAtCurrentPositionInEditor(Caret caret, final PsiFile psiFile) {
  int caretOffset = caret.getOffset();
  int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionStart() ||
                                          caretOffset == caret.getSelectionEnd()
                                          ? caret.getSelectionStart()
                                          : caretOffset;
  if (caret.hasSelection()) {
    return getLanguageAtOffset(psiFile, mostProbablyCorrectLanguageOffset, caret.getSelectionEnd());
  }

  return PsiUtilCore.getLanguageAtOffset(psiFile, mostProbablyCorrectLanguageOffset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:TextEditorPsiDataProvider.java

示例5: IterationState

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
public IterationState(@NotNull EditorEx editor, int start, int end, boolean useCaretAndSelection, boolean useVirtualSelection, boolean useOnlyFullLineHighlighters) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  myDocument = editor.getDocument();
  myStartOffset = start;

  myEnd = end;
  myEditor = editor;
  myUseOnlyFullLineHighlighters = useOnlyFullLineHighlighters;

  LOG.assertTrue(myStartOffset <= myEnd);
  myHighlighterIterator = useOnlyFullLineHighlighters ? null : editor.getHighlighter().createIterator(start);

  if (!useCaretAndSelection) {
    mySelectionStarts = ArrayUtilRt.EMPTY_INT_ARRAY;
    mySelectionEnds = ArrayUtilRt.EMPTY_INT_ARRAY;
    myVirtualSelectionStarts = ArrayUtilRt.EMPTY_INT_ARRAY;
    myVirtualSelectionEnds = ArrayUtilRt.EMPTY_INT_ARRAY;
  }
  else {
    List<Caret> carets = editor.getCaretModel().getAllCarets();
    mySelectionStarts = new int[carets.size()];
    mySelectionEnds = new int[carets.size()];
    myVirtualSelectionStarts = new int[carets.size()];
    myVirtualSelectionEnds = new int[carets.size()];
    for (int i = 0; i < carets.size(); i++) {
      Caret caret = carets.get(i);
      mySelectionStarts[i] = caret.getSelectionStart();
      mySelectionEnds[i] = caret.getSelectionEnd();
      if (useVirtualSelection) {
        myVirtualSelectionStarts[i] = caret.getSelectionStartPosition().column - editor.offsetToVisualPosition(mySelectionStarts[i]).column;
        myVirtualSelectionEnds[i] = caret.getSelectionEndPosition().column - editor.offsetToVisualPosition(mySelectionEnds[i]).column;
      }
    }
  }

  myFoldingModel = editor.getFoldingModel();
  myFoldTextAttributes = myFoldingModel.getPlaceholderAttributes();
  mySelectionAttributes = editor.getSelectionModel().getTextAttributes();

  myReadOnlyColor = myEditor.getColorsScheme().getColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR);

  CaretModel caretModel = editor.getCaretModel();
  myCaretRowAttributes = editor.isRendererMode() ? null : caretModel.getTextAttributes();
  myDefaultBackground = editor.getColorsScheme().getDefaultBackground();
  myDefaultForeground = editor.getColorsScheme().getDefaultForeground();

  myCaretRowStart = caretModel.getVisualLineStart();
  myCaretRowEnd = caretModel.getVisualLineEnd();

  MarkupModelEx editorMarkup = editor.getMarkupModel();
  myView = new HighlighterSweep(editorMarkup, start, myEnd, useOnlyFullLineHighlighters);

  final MarkupModelEx docMarkup = (MarkupModelEx)DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), true);
  myDoc = new HighlighterSweep(docMarkup, start, myEnd, useOnlyFullLineHighlighters);

  myEndOffset = myStartOffset;

  advance();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:IterationState.java

示例6: calcSelectionEnd

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
private static int calcSelectionEnd(Caret caret) {
  return caret.hasSelection() ? caret.getSelectionEnd() : caret.getOffset();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:CompletionInitializationContext.java

示例7: doExecute

import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
@Override
public void doExecute(Editor editor, @Nullable Caret c, DataContext dataContext) {
  Caret caret = c == null ? editor.getCaretModel().getPrimaryCaret() : c;
  TextRange wordSelectionRange = getSelectionRange(editor, caret);
  boolean notFoundPreviously = getAndResetNotFoundStatus(editor);
  boolean wholeWordSearch = isWholeWordSearch(editor);
  if (caret.hasSelection()) {
    Project project = editor.getProject();
    String selectedText = caret.getSelectedText();
    if (project == null || selectedText == null) {
      return;
    }
    FindManager findManager = FindManager.getInstance(project);

    FindModel model = getFindModel(selectedText, wholeWordSearch);

    findManager.setSelectNextOccurrenceWasPerformed();
    findManager.setFindNextModel(model);

    int searchStartOffset = notFoundPreviously ? 0 : caret.getSelectionEnd();
    FindResult findResult = findManager.findString(editor.getDocument().getCharsSequence(), searchStartOffset, model);
    if (findResult.isStringFound()) {
      boolean caretAdded = FindUtil.selectSearchResultInEditor(editor, findResult, caret.getOffset() - caret.getSelectionStart());
      if (!caretAdded) {
        // this means that the found occurence is already selected
        if (notFoundPreviously) {
          setNotFoundStatus(editor); // to make sure we won't show hint anymore if there are no more occurrences
        }
      }
    }
    else {
      setNotFoundStatus(editor);
      showHint(editor);
    }
  }
  else {
    if (wordSelectionRange == null) {
      return;
    }
    setSelection(editor, caret, wordSelectionRange);
    setWholeWordSearch(editor, true);
  }
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:45,代码来源:SelectNextOccurrenceAction.java


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