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