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


Java SelectionModel.removeSelection方法代碼示例

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


在下文中一共展示了SelectionModel.removeSelection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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();
        }
    }
 
開發者ID:huoguangjin,項目名稱:MultiHighlight,代碼行數:25,代碼來源:MultiHighlightHandler.java

示例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();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:HighlightUsagesHandler.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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();
}
 
開發者ID:consulo,項目名稱:consulo,代碼行數:18,代碼來源:HighlightUsagesHandler.java

示例8: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
    //Get all the required data from data keys
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    //Access document, caret, and selection
    final Document document = editor.getDocument();
    final SelectionModel selectionModel = editor.getSelectionModel();

    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    //New instance of Runnable to make a replacement
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            //  return hex(random.randint(0, 2 ** 64) | 1 << 63)
            // from 0 to 64
            BigInteger rand = new BigInteger(64, new Random());
            rand = rand.or(new BigInteger("1").shiftLeft(63));
            String capnpId = rand.toString(16);
            document.setText( String.format("@0x%s; \n\n", capnpId) + document.getText());
        }
    };
    //Making the replacement
    WriteCommandAction.runWriteCommandAction(project, runnable);
    selectionModel.removeSelection();
}
 
開發者ID:xmonader,項目名稱:sercapnp,代碼行數:28,代碼來源:GenerateCapnpID.java

示例9: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    //Get all the required data from data keys
    final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
    final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT);
    //Access document, caret, and selection
    final Document document = editor.getDocument();
    final SelectionModel selectionModel = editor.getSelectionModel();

    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();

    //Making the replacement
    final String[] pathToDocument = new String[1];
    WriteCommandAction.runWriteCommandAction(project,()->{
        String pathToDocumentArray[] = document.toString().split("file://");
        if(pathToDocumentArray.length==2) {
            pathToDocument[0] = pathToDocumentArray[1].replace("]", "").trim();
        } else {
            pathToDocument[0] = document.toString();
        }
    });

    MarkedTextAsBugDialog markedTextAsBugDialog;
    if(new File(pathToDocument[0]).exists()) {
        markedTextAsBugDialog = new MarkedTextAsBugDialog(project, document.getText(new TextRange(start, end)), pathToDocument[0]);
    } else {
        markedTextAsBugDialog = new MarkedTextAsBugDialog(project, document.getText(new TextRange(start, end)));
    }
    markedTextAsBugDialog.show();
    selectionModel.removeSelection();
}
 
開發者ID:domjos1994,項目名稱:ideaMantis,代碼行數:33,代碼來源:MarkedTextAsBugEditorAction.java

示例10: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent actionEvent) {
    final Editor editor = getCurrentEditor(actionEvent);
    if (!hasEditorSelectedText(editor)) {
        return;
    }
    Document document = editor.getDocument();
    SelectionModel selectionModel = editor.getSelectionModel();
    Runnable replacementProcess = getReplacementRunnable(document, selectionModel);
    Project project = actionEvent.getRequiredData(CommonDataKeys.PROJECT);
    WriteCommandAction.runWriteCommandAction(project, replacementProcess);
    selectionModel.removeSelection();
}
 
開發者ID:dnltsk,項目名稱:intellij-geocoding-plugin,代碼行數:14,代碼來源:AbstractGeocodeAction.java

示例11: genericHandling

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private boolean genericHandling(Editor editor, DataContext dataContext, SelectionModel selectionModel,
		PsiFile psiFile) {
	int caretOffset = editor.getCaretModel().getOffset();
	PsiElement elementAtCaret = PsiUtilBase.getElementAtCaret(editor);
	if (elementAtCaret instanceof PsiPlainText) {
		return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
	} else if (elementAtCaret instanceof PsiWhiteSpace) {
		elementAtCaret = PsiUtilBase.getElementAtOffset(psiFile, caretOffset - 1);
	}

	if (elementAtCaret == null || elementAtCaret instanceof PsiWhiteSpace) {
		return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
	} else {
		TextRange textRange = elementAtCaret.getTextRange();
		if (textRange.getLength() == 0) {
			return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
		}
		selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
		String selectedText = selectionModel.getSelectedText();

		if (selectedText != null && selectedText.contains("\n")) {
			selectionModel.removeSelection();
			return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
		}
		if (Style.isQuoted(selectedText)) {
			selectionModel.setSelection(selectionModel.getSelectionStart() + 1,
					selectionModel.getSelectionEnd() - 1);
		}

		if (caretOffset < selectionModel.getSelectionStart()) {
			editor.getCaretModel().moveToOffset(selectionModel.getSelectionStart());
		}
		if (caretOffset > selectionModel.getSelectionEnd()) {
			editor.getCaretModel().moveToOffset(selectionModel.getSelectionEnd());
		}
		return true;
	}
}
 
開發者ID:krasa,項目名稱:StringManipulation,代碼行數:39,代碼來源:AbstractCaseConvertingAction.java

示例12: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
  //Get all the required data from data keys
  final Editor editor = anActionEvent.getRequiredData(CommonDataKeys.EDITOR);
  final Project project = anActionEvent.getRequiredData(CommonDataKeys.PROJECT);

  final SelectionModel selectionModel = editor.getSelectionModel();


  Runnable runnable = new Runnable() {
    @Override
    public void run() {

      //Get Basepath for project
      String basePath = project.getBasePath();

      try {

      //Array list for all found filenames
      List<String> filenames = new ArrayList<String>();
      String currentlySelectedPattern = selectionModel.getSelectedText();

        //Clean search for multiple select scenarious {{> atoms-text-paragraph-medium}}
        currentlySelectedPattern = currentlySelectedPattern.trim();

        //TODO Replace with nice Regex ASAP
        currentlySelectedPattern = currentlySelectedPattern.replace("{{> ", "");
        currentlySelectedPattern = currentlySelectedPattern.replace("{{>", "");
        currentlySelectedPattern = currentlySelectedPattern.replace(" }}", "");
        currentlySelectedPattern = currentlySelectedPattern.replace("}}", "");

        currentlySelectedPattern = currentlySelectedPattern.trim();

      //Path to patterns
      getFileNames(currentlySelectedPattern.toLowerCase(), filenames, Paths.get(basePath + "/source/_patterns"));

      //File found
      if(filenames.get(0) != null)
      {
        VirtualFile fileToOpen = LocalFileSystem.getInstance().findFileByPath(filenames.get(0));
        FileEditorManager.getInstance(project).openFile(fileToOpen, true);
      }

      }catch(Exception e)
      {
        System.out.println("No pattern found");
      }

    }
  };

  runnable.run();

  selectionModel.removeSelection();
}
 
開發者ID:a-bailey,項目名稱:PHPStorm-PatternlabsHelper,代碼行數:56,代碼來源:PatternFinder.java

示例13: checkAutoPopup

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public Result checkAutoPopup(char c, Project project, Editor editor, PsiFile psiFile) {
  // TODO[oleg] provide adequate API not to use this hack
  // beforeCharTyped always works with removed selection
  SelectionModel selectionModel = editor.getSelectionModel();
  if(CodeInsightSettings.getInstance().SURROUND_SELECTION_ON_QUOTE_TYPED &&  selectionModel.hasSelection() && isDelimiter(c)) {
    String selectedText = selectionModel.getSelectedText();
    if (selectedText.length() < 1) {
      return super.checkAutoPopup(c, project, editor, psiFile);
    }
    
    final int selectionStart = selectionModel.getSelectionStart();
    final int selectionEnd = selectionModel.getSelectionEnd();
    if (selectedText.length() > 1) {
      final char firstChar = selectedText.charAt(0);
      final char lastChar = selectedText.charAt(selectedText.length() - 1);
      if (isSimilarDelimiters(firstChar, c) && lastChar == getMatchingDelimiter(firstChar) &&
          (isQuote(firstChar) || firstChar != c) && !shouldSkipReplacementOfQuotesOrBraces(psiFile, editor, selectedText, c) &&
          selectedText.indexOf(lastChar, 1) == selectedText.length() - 1) {
        selectedText = selectedText.substring(1, selectedText.length() - 1);
      }
    }
    final int caretOffset = selectionModel.getSelectionStart();
    final char c2 = getMatchingDelimiter(c);
    final String newText = String.valueOf(c) + selectedText + c2;
    myLtrSelection = selectionModel.getLeadSelectionOffset() != selectionModel.getSelectionEnd();
    if (editor instanceof EditorEx) {
      myRestoreStickySelection = ((EditorEx)editor).isStickySelection();
    }
    else {
      myRestoreStickySelection = false;
    }
    selectionModel.removeSelection();
    editor.getDocument().replaceString(selectionStart, selectionEnd, newText);
    if (Registry.is("editor.smarterSelectionQuoting")) {
      myReplacedTextRange = new TextRange(caretOffset + 1, caretOffset + newText.length() - 1);
    } else {
      myReplacedTextRange = new TextRange(caretOffset, caretOffset + newText.length());
    }
    return Result.STOP;
  }
  return super.checkAutoPopup(c, project, editor, psiFile);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:44,代碼來源:SelectionQuotingTypedHandler.java

示例14: invokeImpl

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public boolean invokeImpl(Editor editor, PsiFile file, String newName) {
    final SelectionModel selectionModel = editor.getSelectionModel();
    if (!selectionModel.hasSelection()) {
        return false;
    }

    int startOffset = selectionModel.getSelectionStart();
    PsiElement start = file.findElementAt(startOffset);
    if (start instanceof PsiWhiteSpace) {
        if ((start = PsiTreeUtil.nextLeaf(start)) != null) {
            startOffset = start.getTextOffset();
        }
    }

    int endOffset = selectionModel.getSelectionEnd();
    PsiElement end = file.findElementAt(endOffset - 1);
    if (end instanceof PsiWhiteSpace) {
        if ((end = PsiTreeUtil.prevLeaf(end)) != null) {
            endOffset = end.getTextRange().getEndOffset();
        }
    }

    if (start == null || end == null) {
        return false;
    }

    final PsiElement parent = start.getParent();
    if (!(parent instanceof XmlTag || parent instanceof XmlComment)) {
        return false;
    }

    if (start == end) {
        if (start.getTextRange().getStartOffset() != startOffset) {
            return false;
        }
        if (end.getTextRange().getEndOffset() != endOffset) {
            return false;
        }

        if (extractFrom(start, end, newName)) {
            // tests dislike empty selection
            selectionModel.removeSelection();
            return true;
        }
    } else {
        final XmlElement startTag = PsiTreeUtil.getParentOfType(start, XmlTag.class, XmlComment.class);
        if (startTag == null) {
            return false;
        }
        if (startTag.getTextRange().getStartOffset() != startOffset) {
            return false;
        }

        final XmlElement endTag = PsiTreeUtil.getParentOfType(end, XmlTag.class, XmlComment.class);
        if (endTag == null) {
            return false;
        }
        if (endTag.getTextRange().getEndOffset() != endOffset) {
            return false;
        }

        if (startTag != endTag) {
            if (startTag.getParent() != endTag.getParent()) {
                return false;
            }
        }
        if (extractFrom(startTag, endTag, newName)) {
            // tests dislike empty selection
            selectionModel.removeSelection();
            return true;
        }
    }
    return false;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:75,代碼來源:XsltExtractTemplateAction.java

示例15: 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]);
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:47,代碼來源:ToggleCaseAction.java


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