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


Java CommandProcessor.setCurrentCommandGroupId方法代码示例

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


在下文中一共展示了CommandProcessor.setCurrentCommandGroupId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteCharAtCaret

import com.intellij.openapi.command.CommandProcessor; //导入方法依赖的package包/类
public static void deleteCharAtCaret(Editor editor) {
  int lineNumber = editor.getCaretModel().getLogicalPosition().line;
  int afterLineEnd = EditorModificationUtil.calcAfterLineEnd(editor);
  Document document = editor.getDocument();
  int offset = editor.getCaretModel().getOffset();
  if (afterLineEnd < 0
      // There is a possible case that caret is located right before the soft wrap position at the last logical line
      // (popular use case with the soft wraps at the commit message dialog).
      || (offset < document.getTextLength() - 1 && editor.getSoftWrapModel().getSoftWrap(offset) != null)) {
    FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(offset);
    if (region != null && region.shouldNeverExpand()) {
      document.deleteString(region.getStartOffset(), region.getEndOffset());
      editor.getCaretModel().moveToOffset(region.getStartOffset());
    }
    else {
      document.deleteString(offset, offset + 1);
      editor.getCaretModel().moveToOffset(offset);
    }
    return;
  }

  if (lineNumber + 1 >= document.getLineCount()) return;

  // Do not group delete newline and other deletions.
  CommandProcessor commandProcessor = CommandProcessor.getInstance();
  commandProcessor.setCurrentCommandGroupId(null);

  int nextLineStart = document.getLineStartOffset(lineNumber + 1);
  int nextLineEnd = document.getLineEndOffset(lineNumber + 1);
  if (nextLineEnd - nextLineStart > 0) {
    StringBuilder buf = new StringBuilder();
    StringUtil.repeatSymbol(buf, ' ', afterLineEnd);
    document.insertString(getCaretLineStart(editor) + getCaretLineLength(editor), buf.toString());
    nextLineStart = document.getLineStartOffset(lineNumber + 1);
  }
  int thisLineEnd = document.getLineEndOffset(lineNumber);
  document.deleteString(thisLineEnd, nextLineStart);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:DeleteAction.java

示例2: doBackSpaceAtCaret

import com.intellij.openapi.command.CommandProcessor; //导入方法依赖的package包/类
private static void doBackSpaceAtCaret(@NotNull Editor editor) {
  if(editor.getSelectionModel().hasSelection()) {
    EditorModificationUtil.deleteSelectedText(editor);
    return;
  }

  int lineNumber = editor.getCaretModel().getLogicalPosition().line;
  int colNumber = editor.getCaretModel().getLogicalPosition().column;
  Document document = editor.getDocument();
  int offset = editor.getCaretModel().getOffset();
  if(colNumber > 0) {
    if(EditorModificationUtil.calcAfterLineEnd(editor) > 0) {
      int columnShift = -1;
      editor.getCaretModel().moveCaretRelatively(columnShift, 0, false, false, true);
    }
    else {
      EditorModificationUtil.scrollToCaret(editor);
      editor.getSelectionModel().removeSelection();

      FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(offset - 1);
      if (region != null && region.shouldNeverExpand()) {
        document.deleteString(region.getStartOffset(), region.getEndOffset());
        editor.getCaretModel().moveToOffset(region.getStartOffset());
      }
      else {
        document.deleteString(offset - 1, offset);
        editor.getCaretModel().moveToOffset(offset - 1, true);
      }
    }
  }
  else if(lineNumber > 0) {
    int separatorLength = document.getLineSeparatorLength(lineNumber - 1);
    int lineEnd = document.getLineEndOffset(lineNumber - 1) + separatorLength;
    document.deleteString(lineEnd - separatorLength, lineEnd);
    editor.getCaretModel().moveToOffset(lineEnd - separatorLength);
    EditorModificationUtil.scrollToCaret(editor);
    editor.getSelectionModel().removeSelection();
    // Do not group delete newline and other deletions.
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.setCurrentCommandGroupId(null);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:BackspaceAction.java


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