本文整理匯總了Java中com.intellij.openapi.editor.SelectionModel.selectWordAtCaret方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectionModel.selectWordAtCaret方法的具體用法?Java SelectionModel.selectWordAtCaret怎麽用?Java SelectionModel.selectWordAtCaret使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.SelectionModel
的用法示例。
在下文中一共展示了SelectionModel.selectWordAtCaret方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleNoUsageTargets
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
/**
* {@link com.intellij.codeInsight.highlighting.HighlightUsagesHandler#handleNoUsageTargets(PsiFile,
* Editor, SelectionModel, Project)}
*/
private static void handleNoUsageTargets(PsiFile file, @NotNull Editor editor,
@NotNull Project project) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) {
return;
}
final SelectionModel selectionModel = editor.getSelectionModel();
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
// LOG.assertTrue(selection != null);
if (selection != null) {
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
}
}
searchSelection(editor, project);
selectionModel.removeSelection();
}
}
示例2: handleNoUsageTargets
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private static void handleNoUsageTargets(PsiFile file,
@NotNull Editor editor,
SelectionModel selectionModel,
@NotNull Project project) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) return;
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
LOG.assertTrue(selection != null);
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
}
}
doRangeHighlighting(editor, project);
selectionModel.removeSelection();
}
示例3: replaceWordSimple
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private void replaceWordSimple(final CharSequence selectedValue)
{
final Project project = editor.getProject();
final Document document = editor.getDocument();
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(true);
}
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
Runnable runnable = new Runnable()
{
@Override
public void run()
{
document.replaceString(start, end, selectedValue);
}
};
//Making the replacement
WriteCommandAction.runWriteCommandAction(project, runnable);
selectionModel.removeSelection();
}
示例4: handleNoUsageTargets
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private static void handleNoUsageTargets(PsiFile file,
@Nonnull Editor editor,
SelectionModel selectionModel,
@Nonnull Project project) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) return;
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
LOG.assertTrue(selection != null);
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
}
}
doRangeHighlighting(editor, project);
selectionModel.removeSelection();
}
示例5: searchSelection
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private static void searchSelection(Editor editor, Project project) {
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(false);
}
final String text = selectionModel.getSelectedText();
if (text == null) {
return;
}
if (editor instanceof EditorWindow) {
// highlightUsages selection in the whole editor, not injected fragment only
editor = ((EditorWindow) editor).getDelegate();
}
EditorSearchSession oldSearch = EditorSearchSession.get(editor);
if (oldSearch != null) {
if (oldSearch.hasMatches()) {
String oldText = oldSearch.getTextInField();
if (!oldSearch.getFindModel().isRegularExpressions()) {
oldText = StringUtil.escapeToRegexp(oldText);
oldSearch.getFindModel().setRegularExpressions(true);
}
String newText = oldText + '|' + StringUtil.escapeToRegexp(text);
oldSearch.setTextInField(newText);
return;
}
}
EditorSearchSession.start(editor, project).getFindModel().setRegularExpressions(false);
}
示例6: invoke
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public static void invoke(@NotNull final Project project, @NotNull final Editor editor, final PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
final SelectionModel selectionModel = editor.getSelectionModel();
if (file == null && !selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(false);
}
if (file == null || selectionModel.hasSelection()) {
doRangeHighlighting(editor, project);
return;
}
final HighlightUsagesHandlerBase handler = createCustomHandler(editor, file);
if (handler != null) {
final String featureId = handler.getFeatureId();
if (featureId != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(featureId);
}
handler.highlightUsages();
return;
}
DumbService.getInstance(project).withAlternativeResolveEnabled(new Runnable() {
@Override
public void run() {
UsageTarget[] usageTargets = getUsageTargets(editor, file);
if (usageTargets == null) {
handleNoUsageTargets(file, editor, selectionModel, project);
return;
}
boolean clearHighlights = isClearHighlights(editor);
for (UsageTarget target : usageTargets) {
target.highlightUsages(file, editor, clearHighlights);
}
}
});
}
示例7: getOriginalWord
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private String getOriginalWord(Editor editor)
{
SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.hasSelection()) {
return selectionModel.getSelectedText();
}
selectionModel.selectWordAtCaret(true);
return selectionModel.getSelectedText();
}
示例8: selectText
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
protected void selectText(Editor editor) {
SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
// if whitespace is at caret, the complete document would be selected, therefore check this first
if (!isWhitespaceAtCaret(editor)) {
selectionModel.selectWordAtCaret(false);
}
}
}
示例9: invoke
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public static void invoke(@Nonnull final Project project, @Nonnull final Editor editor, final PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
final SelectionModel selectionModel = editor.getSelectionModel();
if (file == null && !selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(false);
}
if (file == null || selectionModel.hasSelection()) {
doRangeHighlighting(editor, project);
return;
}
final HighlightUsagesHandlerBase handler = createCustomHandler(editor, file);
if (handler != null) {
final String featureId = handler.getFeatureId();
if (featureId != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(featureId);
}
handler.highlightUsages();
return;
}
DumbService.getInstance(project).withAlternativeResolveEnabled(() -> {
UsageTarget[] usageTargets = getUsageTargets(editor, file);
if (usageTargets == null) {
handleNoUsageTargets(file, editor, selectionModel, project);
return;
}
boolean clearHighlights = isClearHighlights(editor);
for (UsageTarget target : usageTargets) {
target.highlightUsages(file, editor, clearHighlights);
}
});
}
示例10: executeWriteAction
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
final SelectionModel selectionModel = editor.getSelectionModel();
final int[] starts;
final int[] ends;
LogicalPosition blockStart = null;
LogicalPosition blockEnd = null;
if (selectionModel.hasBlockSelection()) {
starts = selectionModel.getBlockSelectionStarts();
ends = selectionModel.getBlockSelectionEnds();
blockStart = selectionModel.getBlockStart();
blockEnd = selectionModel.getBlockEnd();
}
else {
if (!selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(true);
}
starts = new int[] {selectionModel.getSelectionStart()};
ends = new int[] {selectionModel.getSelectionEnd()};
}
selectionModel.removeBlockSelection();
selectionModel.removeSelection();
for (int i = 0; i < starts.length; i++) {
int startOffset = starts[i];
int endOffset = ends[i];
StringBuilder builder = new StringBuilder();
final String text = editor.getDocument().getCharsSequence().subSequence(startOffset, endOffset).toString();
toCase(builder, text, true);
if (text.equals(builder.toString())) {
toCase(builder, text, false);
}
editor.getDocument().replaceString(startOffset, endOffset, builder.toString());
}
if (blockStart != null) {
selectionModel.setBlockSelection(blockStart, blockEnd);
}
else {
selectionModel.setSelection(starts[0], ends[0]);
}
}
示例11: invoke
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public static void invoke(@NotNull Project project, @NotNull Editor editor, PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
SelectionModel selectionModel = editor.getSelectionModel();
if (file == null && !selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(false);
}
if (file == null || selectionModel.hasSelection()) {
doRangeHighlighting(editor, project);
return;
}
final HighlightUsagesHandlerBase handler = createCustomHandler(editor, file);
if (handler != null) {
handler.highlightUsages();
return;
}
UsageTarget[] usageTargets = UsageTargetUtil.findUsageTargets(editor, file);
if (usageTargets == null) {
PsiElement targetElement = getTargetElement(editor, file);
if (targetElement != null) {
if (!(targetElement instanceof NavigationItem)) {
targetElement = targetElement.getNavigationElement();
}
if (targetElement instanceof NavigationItem) {
usageTargets = new UsageTarget[]{new PsiElement2UsageTargetAdapter(targetElement)};
}
}
}
if (usageTargets == null) {
PsiReference ref = TargetElementUtilBase.findReference(editor);
if (ref instanceof PsiPolyVariantReference) {
ResolveResult[] results = ((PsiPolyVariantReference)ref).multiResolve(false);
if (results.length > 0) {
usageTargets = new UsageTarget[results.length];
for (int i = 0; i < results.length; ++i) {
usageTargets[i] = new PsiElement2UsageTargetAdapter(results[i].getElement());
}
}
}
}
if (usageTargets == null) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) return;
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
LOG.assertTrue(selection != null);
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
return;
}
}
doRangeHighlighting(editor, project);
selectionModel.removeSelection();
return;
}
boolean clearHighlights = isClearHighlights(editor);
for (UsageTarget target : usageTargets) {
target.highlightUsages(file, editor, clearHighlights);
}
}