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


Java SelectionModel.hasBlockSelection方法代碼示例

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


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

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

示例2: getPositionText

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private String getPositionText(Editor editor) {
  if (!editor.isDisposed() && myStatusBar != null) {
    StringBuilder message = new StringBuilder();

    SelectionModel selectionModel = editor.getSelectionModel();
    if (selectionModel.hasBlockSelection()) {
      LogicalPosition start = selectionModel.getBlockStart();
      LogicalPosition end = selectionModel.getBlockEnd();
      if (start == null || end == null) {
        throw new IllegalStateException(String.format(
          "Invalid selection model state detected: 'blockSelection' property is 'true' but selection start position (%s) or "
          + "selection end position (%s) is undefined", start, end
        ));
      }
      appendLogicalPosition(start, message);
      message.append("-");
      appendLogicalPosition(
        new LogicalPosition(Math.abs(end.line - start.line), Math.max(0, Math.abs(end.column - start.column) - 1)),
        message
      );
    }
    else {
      LogicalPosition caret = editor.getCaretModel().getLogicalPosition();

      appendLogicalPosition(caret, message);
      if (selectionModel.hasSelection()) {
        int len = Math.abs(selectionModel.getSelectionStart() - selectionModel.getSelectionEnd());
        if (len != 0) message.append("/").append(len);
      }
    }

    return message.toString();
  }
  else {
    return "";
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:38,代碼來源:PositionPanel.java

示例3: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void executeWriteAction(@NotNull Editor editor, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int prevSymbolOffset = editor.getCaretModel().getOffset() - 1;
  if (prevSymbolOffset < 0) {
    return;
  }
  
  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(prevSymbolOffset);
  final boolean doHungryCheck = !selectionModel.hasSelection() && !selectionModel.hasBlockSelection() && StringUtil.isWhiteSpace(c);
  final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
  handler.execute(editor, dataContext);

  if (!doHungryCheck) {
    return;
  }
  
  final int endOffset = prevSymbolOffset;
  if (endOffset > document.getTextLength()) {
    return;
  }
  int startOffset = CharArrayUtil.shiftBackward(text, endOffset - 1, "\t \n");
  if (startOffset < 0) {
    // No non-white space symbol before the current caret offset has been found.
    startOffset = 0;
  }
  else {
    // Offset now points to the first non-white space symbol before the caret.
    // Increment it to point to the first white space symbol instead.
    startOffset++;
  }
  if (startOffset >= endOffset) {
    return;
  }
  document.deleteString(startOffset, endOffset);
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:39,代碼來源:HungryBackspaceAction.java

示例4: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void executeWriteAction(final Editor editor, DataContext dataContext) {
  final SelectionModel selectionModel = editor.getSelectionModel();
  int changedLines = 0;
  if (selectionModel.hasSelection()) {
    changedLines = performAction(editor, new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()));
  }
  else if (selectionModel.hasBlockSelection()) {
    final int[] starts = selectionModel.getBlockSelectionStarts();
    final int[] ends = selectionModel.getBlockSelectionEnds();
    for (int i = 0; i < starts.length; i++) {
      changedLines += performAction(editor, new TextRange(starts [i], ends [i]));
    }
  }
  else {
    changedLines += performAction(editor, new TextRange(0, editor.getDocument().getTextLength()));
  }
  if (changedLines == 0) {
    HintManager.getInstance().showInformationHint(editor, "All lines already have requested indentation");
  }
  else {
    HintManager.getInstance().showInformationHint(editor, "Changed indentation in " + changedLines + (changedLines == 1 ? " line" : " lines"));
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:ConvertIndentsActionBase.java

示例5: isAvailable

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  final SelectionModel selectionModel = editor.getSelectionModel();
  if (!(file instanceof GroovyFileBase)) return false;
  if (selectionModel.hasBlockSelection()) return false;

  if (selectionModel.hasSelection()) {
    final HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(selectionModel.getSelectionStart());
    final int end = selectionModel.getSelectionEnd();
    while (!iterator.atEnd()) {
      if (iterator.getTokenType() == GroovyTokenTypes.mSEMI) return true;
      if (iterator.getStart() > end) return false;
      iterator.advance();
    }
    return false;
  }

  int offset = editor.getCaretModel().getOffset();
  if (offset >= editor.getDocument().getTextLength()) offset = editor.getDocument().getTextLength() - 1;
  final PsiElement element = file.findElementAt(offset);
  if (element == null) return false;
  if (element.getNode().getElementType() == GroovyTokenTypes.mSEMI) return true;

  final PsiElement next = PsiTreeUtil.nextLeaf(element);
  if (next != null && next.getNode().getElementType() == GroovyTokenTypes.mSEMI) return true;


  final PsiElement prev = PsiTreeUtil.prevLeaf(element);
  if (prev != null && prev.getNode().getElementType() == GroovyTokenTypes.mSEMI) return true;

  return false;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:33,代碼來源:RemoveUnnecessarySemicolonsIntention.java

示例6: isEnabled

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  SelectionModel selectionModel = editor.getSelectionModel();
  return //PlatformDataKeys.IS_MODAL_CONTEXT.getData(dataContext) != Boolean.TRUE &&
         (selectionModel.hasSelection() || selectionModel.hasBlockSelection());
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:7,代碼來源:EscapeAction.java

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

示例8: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getContentComponent()));
  if (project == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, dataContext);
    }
    return;
  }

  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  if (file == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, dataContext);
    }
    return;
  }

  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection() && !selectionModel.hasBlockSelection()) {
    if (Registry.is(CopyAction.SKIP_COPY_AND_CUT_FOR_EMPTY_SELECTION_KEY)) {
      return;
    }
    selectionModel.selectLineAtCaret();
    if (!selectionModel.hasSelection()) return;
  }

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

  EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_COPY).execute(editor, dataContext);

  if (start != end) {
    // There is a possible case that 'sticky selection' is active. It's automatically removed on copying then, so, we explicitly
    // remove the text.
    editor.getDocument().deleteString(start, end);
  }
  else {
    EditorModificationUtil.deleteSelectedText(editor);
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:43,代碼來源:CutHandler.java

示例9: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
  if (project == null) {
    return;
  }
  
  final Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext());
  if (editor == null) {
    return;
  }
  
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  Document document = editor.getDocument();
  documentManager.commitDocument(document);
  
  final PsiFile file = documentManager.getPsiFile(document);
  if (file == null) {
    return;
  }

  final List<TextRange> ranges = new ArrayList<TextRange>();
  SelectionModel selectionModel = editor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    ranges.add(TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()));
  }
  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]));
    }
  }
  else {
    ranges.add(TextRange.create(0, document.getTextLength()));
  }
  
  final ArrangementEngine engine = ServiceManager.getService(project, ArrangementEngine.class);
  try {
    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
      @Override
      public void run() {
        engine.arrange(editor, file, ranges); 
      }
    }, getTemplatePresentation().getText(), null);
  }
  finally {
    documentManager.commitDocument(document);
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:51,代碼來源:RearrangeCodeAction.java


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