本文整理匯總了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);
}
}