当前位置: 首页>>代码示例>>Java>>正文


Java SelectionModel.getBlockSelectionStarts方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.SelectionModel.getBlockSelectionStarts方法的典型用法代码示例。如果您正苦于以下问题:Java SelectionModel.getBlockSelectionStarts方法的具体用法?Java SelectionModel.getBlockSelectionStarts怎么用?Java SelectionModel.getBlockSelectionStarts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.SelectionModel的用法示例。


在下文中一共展示了SelectionModel.getBlockSelectionStarts方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: performReplaceAll

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
public void performReplaceAll(Editor e) {
  if (!ReadonlyStatusHandler.ensureDocumentWritable(e.getProject(), e.getDocument())) return;
  if (mySearchResults.getFindModel() != null) {
    final FindModel copy = new FindModel();
    copy.copyFrom(mySearchResults.getFindModel());

    final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();

    final int offset;
    if (!selectionModel.hasSelection() || copy.isGlobal()) {
      copy.setGlobal(true);
      offset = 0;
    } else {
      offset = selectionModel.getBlockSelectionStarts()[0];
    }
    FindUtil.replace(e.getProject(), e, offset, copy, this);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LivePreviewController.java

示例3: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
  PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
  if (editor == null || file == null) return;
  final Project project = file.getProject();
  CommandProcessorEx commandProcessor = (CommandProcessorEx)CommandProcessorEx.getInstance();
  Object commandToken = commandProcessor.startCommand(project, e.getPresentation().getText(), e.getPresentation().getText(), UndoConfirmationPolicy.DEFAULT);
  AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
  try {
    final SelectionModel selectionModel = editor.getSelectionModel();
    int[] starts = selectionModel.getBlockSelectionStarts();
    int[] ends = selectionModel.getBlockSelectionEnds();

    int startOffset = starts.length == 0? 0 : starts[0];
    int endOffset = ends.length == 0? editor.getDocument().getTextLength() : ends[ends.length - 1];

    perform(project, editor.getDocument(), startOffset, endOffset);
  }
  finally {
    token.finish();
    commandProcessor.finishCommand(project, commandToken, null);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ToggleHighlightingMarkupAction.java

示例4: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext());
  PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext());
  if (editor == null || file == null) return;
  final Project project = file.getProject();
  CommandProcessorEx commandProcessor = (CommandProcessorEx)CommandProcessorEx.getInstance();
  Object commandToken = commandProcessor.startCommand(project, e.getPresentation().getText(), e.getPresentation().getText(), UndoConfirmationPolicy.DEFAULT);
  AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
  try {
    final SelectionModel selectionModel = editor.getSelectionModel();
    int[] starts = selectionModel.getBlockSelectionStarts();
    int[] ends = selectionModel.getBlockSelectionEnds();

    int startOffset = starts.length == 0? 0 : starts[0];
    int endOffset = ends.length == 0? editor.getDocument().getTextLength() : ends[ends.length - 1];

    perform(project, editor.getDocument(), startOffset, endOffset);
  }
  finally {
    token.finish();
    commandProcessor.finishCommand(project, commandToken, null);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:ToggleHighlightingMarkupAction.java

示例5: performReplaceAll

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
public void performReplaceAll(Editor e) {
  Project project = mySearchResults.getProject();
  if (!ReadonlyStatusHandler.ensureDocumentWritable(project, e.getDocument())) return;
  if (mySearchResults.getFindModel() != null) {
    final FindModel copy = new FindModel();
    copy.copyFrom(mySearchResults.getFindModel());

    final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();

    final int offset;
    if (!selectionModel.hasSelection() || copy.isGlobal()) {
      copy.setGlobal(true);
      offset = 0;
    } else {
      offset = selectionModel.getBlockSelectionStarts()[0];
    }
    FindUtil.replace(project, e, offset, copy, this);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:LivePreviewController.java

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

示例7: updateInSelectionHighlighters

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private void updateInSelectionHighlighters() {
  if (mySearchResults.getEditor() == null) return;
  final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
  int[] starts = selectionModel.getBlockSelectionStarts();
  int[] ends = selectionModel.getBlockSelectionEnds();

  final HashSet<RangeHighlighter> toRemove = new HashSet<RangeHighlighter>();
  Set<RangeHighlighter> toAdd = new HashSet<RangeHighlighter>();
  for (RangeHighlighter highlighter : myHighlighters) {
    if (!highlighter.isValid()) continue;
    boolean intersectsWithSelection = false;
    for (int i = 0; i < starts.length; ++i) {
      TextRange selectionRange = new TextRange(starts[i], ends[i]);
      intersectsWithSelection = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) &&
                                selectionRange.getEndOffset() != highlighter.getStartOffset() &&
                                highlighter.getEndOffset() != selectionRange.getStartOffset();
      if (intersectsWithSelection) break;
    }

    final Object userData = highlighter.getUserData(IN_SELECTION_KEY);
    if (userData != null) {
      if (!intersectsWithSelection) {
        if (userData == IN_SELECTION2) {
          HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), highlighter);
          toRemove.add(highlighter);
        } else {
          highlighter.putUserData(IN_SELECTION_KEY, null);
        }
      }
    } else if (intersectsWithSelection) {
      TextRange cursor = mySearchResults.getCursor();
      if (cursor != null && highlighter.getStartOffset() == cursor.getStartOffset() &&
          highlighter.getEndOffset() == cursor.getEndOffset()) continue;
      final RangeHighlighter toAnnotate = highlightRange(new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset()),
                                                               new TextAttributes(null, null, Color.WHITE, EffectType.ROUNDED_BOX, 0), toAdd);
      highlighter.putUserData(IN_SELECTION_KEY, IN_SELECTION1);
      toAnnotate.putUserData(IN_SELECTION_KEY, IN_SELECTION2);
    }
  }
  myHighlighters.removeAll(toRemove);
  myHighlighters.addAll(toAdd);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:LivePreview.java

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

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

示例10: updateInSelectionHighlighters

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private void updateInSelectionHighlighters() {
  if (mySearchResults.getEditor() == null) return;
  final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
  int[] starts = selectionModel.getBlockSelectionStarts();
  int[] ends = selectionModel.getBlockSelectionEnds();

  final HashSet<RangeHighlighter> toRemove = new HashSet<RangeHighlighter>();
  Set<RangeHighlighter> toAdd = new HashSet<RangeHighlighter>();
  for (RangeHighlighter highlighter : myHighlighters) {
    boolean intersectsWithSelection = false;
    for (int i = 0; i < starts.length; ++i) {
      TextRange selectionRange = new TextRange(starts[i], ends[i]);
      intersectsWithSelection = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) &&
                                selectionRange.getEndOffset() != highlighter.getStartOffset() &&
                                highlighter.getEndOffset() != selectionRange.getStartOffset();
      if (intersectsWithSelection) break;
    }

    final Object userData = highlighter.getUserData(IN_SELECTION_KEY);
    if (userData != null) {
      if (!intersectsWithSelection) {
        if (userData == IN_SELECTION2) {
          HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), highlighter);
          toRemove.add(highlighter);
        } else {
          highlighter.putUserData(IN_SELECTION_KEY, null);
        }
      }
    } else if (intersectsWithSelection) {
      TextRange cursor = mySearchResults.getCursor();
      if (cursor != null && highlighter.getStartOffset() == cursor.getStartOffset() &&
          highlighter.getEndOffset() == cursor.getEndOffset()) continue;
      final RangeHighlighter toAnnotate = highlightRange(new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset()),
                                                         new TextAttributes(null, null, Color.WHITE, EffectType.ROUNDED_BOX, 0), toAdd);
      highlighter.putUserData(IN_SELECTION_KEY, IN_SELECTION1);
      toAnnotate.putUserData(IN_SELECTION_KEY, IN_SELECTION2);
    }
  }
  myHighlighters.removeAll(toRemove);
  myHighlighters.addAll(toAdd);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:42,代码来源:LivePreview.java


注:本文中的com.intellij.openapi.editor.SelectionModel.getBlockSelectionStarts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。