use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class SearchResults method getSelection.
private static void getSelection(final Editor editor, final FutureResult<int[]> starts, final FutureResult<int[]> ends) {
if (ApplicationManager.getApplication().isDispatchThread()) {
SelectionModel selection = editor.getSelectionModel();
starts.set(selection.getBlockSelectionStarts());
ends.set(selection.getBlockSelectionEnds());
} else {
try {
SwingUtilities.invokeAndWait(() -> {
SelectionModel selection = editor.getSelectionModel();
starts.set(selection.getBlockSelectionStarts());
ends.set(selection.getBlockSelectionEnds());
});
} catch (InterruptedException | InvocationTargetException ignore) {
}
}
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class ConfigureCodeStyleOnSelectedFragment method calculateAffectingSettings.
private static CodeStyleSettingsToShow calculateAffectingSettings(@NotNull Editor editor, @NotNull PsiFile file) {
SelectionModel model = editor.getSelectionModel();
int start = model.getSelectionStart();
int end = model.getSelectionEnd();
CodeStyleSettingsCodeFragmentFilter settingsProvider = new CodeStyleSettingsCodeFragmentFilter(file, new TextRange(start, end));
return CodeFragmentCodeStyleSettingsPanel.calcSettingNamesToShow(settingsProvider);
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class SelectedTextFormatter method reformatSelectedText.
void reformatSelectedText(@NotNull CodeStyleSettings reformatSettings) {
final SelectionModel model = myEditor.getSelectionModel();
if (model.hasSelection()) {
try {
CodeStyleSettingsManager.getInstance(myProject).setTemporarySettings(reformatSettings);
reformatRange(myFile, getSelectedRange());
} finally {
CodeStyleSettingsManager.getInstance(myProject).dropTemporarySettings();
}
}
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class IntroduceHandler method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
if (editor == null || file == null) {
return;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file)) {
return;
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
int caretCount = editor.getCaretModel().getCaretCount();
if (caretCount != 1) {
cannotPerformRefactoring(project, editor);
return;
}
SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.hasSelection()) {
invokeOnSelection(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), project, editor, file);
} else {
int offset = editor.getCaretModel().getOffset();
Pair<List<Target>, Integer> targetInfo = collectTargets(offset, file, editor, project);
List<Target> list = targetInfo.getFirst();
if (list.isEmpty()) {
cannotPerformRefactoring(project, editor);
} else if (list.size() == 1) {
invokeOnTarget(list.get(0), file, editor, project);
} else {
IntroduceTargetChooser.showIntroduceTargetChooser(editor, list, new Pass<Target>() {
@Override
public void pass(final Target target) {
invokeOnTarget(target, file, editor, project);
}
}, "Expressions", targetInfo.getSecond());
}
}
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class RearrangeCodeAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return;
}
final Editor editor = e.getData(CommonDataKeys.EDITOR);
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;
}
SelectionModel model = editor.getSelectionModel();
if (model.hasSelection()) {
new RearrangeCodeProcessor(file, model).run();
} else {
new RearrangeCodeProcessor(file).run();
}
}
Aggregations