本文整理匯總了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;
}
示例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 "";
}
}
示例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);
}
示例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"));
}
}
示例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;
}
示例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());
}
示例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]);
}
}
示例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);
}
}
示例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);
}
}