當前位置: 首頁>>代碼示例>>Java>>正文


Java SelectionModel.hasSelection方法代碼示例

本文整理匯總了Java中com.intellij.openapi.editor.SelectionModel.hasSelection方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectionModel.hasSelection方法的具體用法?Java SelectionModel.hasSelection怎麽用?Java SelectionModel.hasSelection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.editor.SelectionModel的用法示例。


在下文中一共展示了SelectionModel.hasSelection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSelectedText

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
String getSelectedText(Editor editor) {
  SelectionModel selectionModel = editor.getSelectionModel();
  if(selectionModel.hasSelection()){
    return selectionModel.getSelectedText();
  }else {
    final ArrayList<TextRange> ranges = new ArrayList<>();
    final int offset = editor.getCaretModel().getOffset();
    SelectWordUtilCompat.addWordOrLexemeSelection(false, editor, offset, ranges, SelectWordUtilCompat.JAVASCRIPT_IDENTIFIER_PART_CONDITION);
    if(ranges.size()>0){
      return  editor.getDocument().getText(ranges.get(0));
    }else {
      return null;
    }
  }
}
 
開發者ID:dpzxsm,項目名稱:ReactPropTypes-Plugin,代碼行數:17,代碼來源:CommonAction.java

示例2: satisfiedBy

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public boolean satisfiedBy(PsiElement element, @Nullable Editor editor) {
  if (editor == null) {
    return false;
  }
  final SelectionModel selectionModel = editor.getSelectionModel();
  final Document document = editor.getDocument();
  if (selectionModel.hasSelection()) {
    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    if (start < 0 || end < 0 || start > end) {
      // shouldn't happen but http://ea.jetbrains.com/browser/ea_problems/50192
      return false;
    }
    final String text = document.getCharsSequence().subSequence(start, end).toString();
    return indexOfUnicodeEscape(text, 1) >= 0;
  }
  else {
    final CaretModel caretModel = editor.getCaretModel();
    final int lineNumber = document.getLineNumber(caretModel.getOffset());
    final String line = document.getText(new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber)));
    final int column = caretModel.getLogicalPosition().column;
    final int index = indexOfUnicodeEscape(line, column);
    return index >= 0 && column >= index;
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:UnicodeUnescapeIntention.java

示例3: invoke

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  PsiElement element1 = null;
  PsiElement element2 = null;
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    element1 = file.findElementAt(selectionModel.getSelectionStart());
    element2 = file.findElementAt(selectionModel.getSelectionEnd() - 1);
  }
  else {
    final CaretModel caretModel = editor.getCaretModel();
    final Document document = editor.getDocument();
    int lineNumber = document.getLineNumber(caretModel.getOffset());
    if ((lineNumber >= 0) && (lineNumber < document.getLineCount())) {
      element1 = file.findElementAt(document.getLineStartOffset(lineNumber));
      element2 = file.findElementAt(document.getLineEndOffset(lineNumber) - 1);
    }
  }
  if (element1 == null || element2 == null) {
    CommonRefactoringUtil.showErrorHint(project, editor, PyBundle.message("refactoring.introduce.selection.error"), getTitle(),
                                        "members.pull.up");
    return;
  }
  doRefactor(project, element1, element2, editor, file, dataContext);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:PyClassRefactoringHandler.java

示例4: execute

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void execute(final Editor editor, final DataContext dataContext) {
  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }

  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  if (start >= end) {
    return;
  }
  KillRingUtil.copyToKillRing(editor, start, end, false);
  if (myRemove) {
    ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) {
      @Override
      public void run() {
        editor.getDocument().deleteString(start, end);
      }
    });
  } 
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:KillRingSaveAction.java

示例5: checkApplicability

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void checkApplicability(final PsiFile psiFile, final Editor editor) throws IncorrectOperationException {
  PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(psiFile, editor);
  if (literalExpression != null) {
    SelectionModel selectionModel = editor.getSelectionModel();
    if (!selectionModel.hasSelection()) return;
    int start = selectionModel.getSelectionStart();
    int end = selectionModel.getSelectionEnd();
    TextRange textRange = literalExpression.getTextRange();
    if (textRange.contains(start) && textRange.contains(end)) {
      mySelectionRange = new TextRange(start, end);
      return;
    }
  }
  String message = CodeInsightBundle.message("i18nize.error.message");
  throw new IncorrectOperationException(message);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:I18nizeQuickFix.java

示例6: getSelectedRanges

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
protected static List<TextRange> getSelectedRanges(@NotNull SelectionModel selectionModel) {
  final List<TextRange> ranges = new SmartList<TextRange>();
  if (selectionModel.hasSelection()) {
    TextRange range = TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
    ranges.add(range);
  }
  else if (selectionModel.hasBlockSelection()) {
    int[] starts = selectionModel.getBlockSelectionStarts();
    int[] ends = selectionModel.getBlockSelectionEnds();
    for (int i = 0; i < starts.length; i++) {
      ranges.add(TextRange.create(starts[i], ends[i]));
    }
  }

  return ranges;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:AbstractLayoutCodeProcessor.java

示例7: execute

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void execute(Editor editor, DataContext dataContext) {
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    final TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    if (state != null && editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null) {
      final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
      if (lookup != null) {
        selectionModel.removeSelection();
        lookup.hideLookup(true);
        return;
      }
    }
  }

  myOriginalHandler.execute(editor, dataContext);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:EscapeHandler.java

示例8: getNonEmptySelectionRange

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
private static TextRange getNonEmptySelectionRange(Editor editor) {
  if (editor != null) {
    final SelectionModel model = editor.getSelectionModel();

    if (model.hasSelection()) {
      final int start = model.getSelectionStart();
      final int end = model.getSelectionEnd();

      if (start < end) {
        return TextRange.create(start, end);
      }
    }
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:AndroidBaseXmlRefactoringAction.java

示例9: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final MCSettingsProvider settings = MCSettingsProvider.getInstance(e.getProject());
    final Editor editor = e.getData(LangDataKeys.EDITOR);
    if (editor == null)
        return;

    final SelectionModel selectionModel = editor.getSelectionModel();
    String selectedText;

    if (selectionModel.hasSelection()) {
        selectedText = selectionModel.getSelectedText();
    }
    else {
        selectionModel.selectLineAtCaret();
        if (selectionModel.hasSelection()) {
            selectedText = selectionModel.getSelectedText();
            selectionModel.removeSelection();
        }
        else { return; }
    }

    MayaCommInterface maya = new MayaCommInterface(settings.getHost(), settings.getPort());
    maya.connectMayaLog();
    maya.sendCodeToMaya(selectedText);
}
 
開發者ID:cmcpasserby,項目名稱:MayaCharm,代碼行數:27,代碼來源:SendSelectionAction.java

示例10: getContents

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@NotNull
public DiffContent[] getContents() {
  if (myContents != null) return myContents;
  DiffContent clipboardContent = ClipboardVsValueContents.createClipboardContent();
  if (clipboardContent == null) clipboardContent = new SimpleContent("");
  myContents = new DiffContent[2];
  myContents[0] = clipboardContent;

  SelectionModel selectionModel = myEditor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
    myContents[1] = new FragmentContent(DiffContent.fromDocument(getProject(), getDocument()),
                                        range, getProject(), getDocumentFile(getDocument()));
  }
  else {
    myContents [1] = DiffContent.fromDocument(getProject(), getDocument());
  }
  return myContents;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:20,代碼來源:CompareClipboardWithSelection.java

示例11: execute

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void execute(Editor editor, DataContext dataContext) {
  if (!(editor instanceof EditorEx)) {
    return;
  }
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }
  
  EditorEx editorEx = (EditorEx)editor;
  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  final CaretModel caretModel = editor.getCaretModel();
  boolean moveToEnd = caretModel.getOffset() == start;
  editorEx.setStickySelection(false);
  editorEx.setStickySelection(true);
  if (moveToEnd) {
    caretModel.moveToOffset(end);
  }
  else {
    caretModel.moveToOffset(start);
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:SwapSelectionBoundariesAction.java

示例12: execute

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void execute(Editor editor, DataContext dataContext) {
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    final TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    if (state != null && editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null) {
      final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
      if (lookup != null) {
        selectionModel.removeSelection();
        lookup.hide();
        return;
      }
    }
  }

  myOriginalHandler.execute(editor, dataContext);
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:18,代碼來源:EscapeHandler.java

示例13: 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();
}
 
開發者ID:pascaldevink,項目名稱:intellij-thesaurus,代碼行數:27,代碼來源:ThesaurusListPopupStep.java

示例14: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void executeWriteAction(@Nonnull Editor editor, Caret caret, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int caretOffset = editor.getCaretModel().getOffset();
  if (caretOffset < 1) {
    return;
  }

  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(caretOffset - 1);
  if (!selectionModel.hasSelection() && StringUtil.isWhiteSpace(c)) {
    int startOffset = CharArrayUtil.shiftBackward(text, caretOffset - 2, "\t \n") + 1;
    document.deleteString(startOffset, caretOffset);
  }
  else {
    final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
    handler.execute(editor, caret, dataContext);
  }
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:21,代碼來源:HungryBackspaceAction.java

示例15: getSingleLineSelection

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
private static String getSingleLineSelection(@Nonnull Editor editor) {
  final SelectionModel model = editor.getSelectionModel();
  final Document document = editor.getDocument();
  if (!model.hasSelection()) {
    final int offset = editor.getCaretModel().getOffset();
    if (offset <= document.getTextLength()) {
      final int lineNumber = document.getLineNumber(offset);
      final String line = document.getText().substring(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber)).trim();
      if (StringUtil.isNotEmpty(line)) {
        return line;
      }
    }

    return null;
  }
  final int start = model.getSelectionStart();
  final int end = model.getSelectionEnd();
  if (document.getLineNumber(start) == document.getLineNumber(end)) {
    final String selection = document.getText().substring(start, end).trim();
    if (StringUtil.isNotEmpty(selection)) {
      return selection;
    }
  }
  return null;
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:27,代碼來源:FoldLinesLikeThis.java


注:本文中的com.intellij.openapi.editor.SelectionModel.hasSelection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。