本文整理汇总了Java中com.intellij.openapi.editor.Caret.getSelectionStart方法的典型用法代码示例。如果您正苦于以下问题:Java Caret.getSelectionStart方法的具体用法?Java Caret.getSelectionStart怎么用?Java Caret.getSelectionStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.Caret
的用法示例。
在下文中一共展示了Caret.getSelectionStart方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getInjectedEditorForInjectedFile
import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
@NotNull
public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @NotNull Caret hostCaret, @Nullable final PsiFile injectedFile) {
if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor;
Project project = hostEditor.getProject();
if (project == null) project = injectedFile.getProject();
Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile);
if (!(document instanceof DocumentWindowImpl)) return hostEditor;
DocumentWindowImpl documentWindow = (DocumentWindowImpl)document;
if (hostCaret.hasSelection()) {
int selstart = hostCaret.getSelectionStart();
if (selstart != -1) {
int selend = Math.max(selstart, hostCaret.getSelectionEnd());
if (!documentWindow.containsRange(selstart, selend)) {
// selection spreads out the injected editor range
return hostEditor;
}
}
}
if (!documentWindow.isValid()) {
return hostEditor; // since the moment we got hold of injectedFile and this moment call, document may have been dirtied
}
return EditorWindowImpl.create(documentWindow, (EditorImpl)hostEditor, injectedFile);
}
示例5: 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);
}
示例6: 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();
}
示例7: calcStartOffset
import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
public static int calcStartOffset(Caret caret) {
return caret.hasSelection() ? caret.getSelectionStart() : caret.getOffset();
}
示例8: doExecute
import com.intellij.openapi.editor.Caret; //导入方法依赖的package包/类
@Override
public void doExecute(final Editor editor, @Nullable Caret c, DataContext dataContext) {
Caret caret = c == null ? editor.getCaretModel().getPrimaryCaret() : c;
boolean wholeWordsSearch = false;
if (!caret.hasSelection()) {
TextRange wordSelectionRange = getSelectionRange(editor, caret);
if (wordSelectionRange != null) {
setSelection(editor, caret, wordSelectionRange);
wholeWordsSearch = true;
}
}
String selectedText = caret.getSelectedText();
Project project = editor.getProject();
if (project == null || selectedText == null) {
return;
}
int caretShiftFromSelectionStart = caret.getOffset() - caret.getSelectionStart();
final FindManager findManager = FindManager.getInstance(project);
final FindModel model = getFindModel(selectedText, wholeWordsSearch);
FindUtil.selectSearchResultsInEditor(editor, new Iterator<FindResult>() {
FindResult findResult = findManager.findString(editor.getDocument().getCharsSequence(), 0, model);
@Override
public boolean hasNext() {
return findResult.isStringFound();
}
@Override
public FindResult next() {
FindResult result = findResult;
findResult = findManager.findString(editor.getDocument().getCharsSequence(), findResult.getEndOffset(), model);
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}, caretShiftFromSelectionStart);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}