本文整理汇总了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());
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例6: calcSelectionEnd
import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
private static int calcSelectionEnd(Caret caret) {
return caret.hasSelection() ? caret.getSelectionEnd() : caret.getOffset();
}
示例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);
}