本文整理汇总了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);
}
示例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);
}
}