use of com.intellij.openapi.editor.SelectionModel in project intellij-plugins by JetBrains.
the class DartExtractLocalVariableRefactoringTest method createRefactoring.
@NotNull
private ServerExtractLocalVariableRefactoring createRefactoring(String filePath) {
((CodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
final PsiFile psiFile = myFixture.configureByFile(filePath);
ApplicationManager.getApplication().runWriteAction(() -> {
try {
VfsUtil.saveText(psiFile.getVirtualFile(), StringUtil.convertLineSeparators(psiFile.getText(), "\r\n"));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
// make sure server is warmed up
myFixture.doHighlighting();
// find the Element to rename
final SelectionModel selectionModel = getEditor().getSelectionModel();
int offset = selectionModel.getSelectionStart();
final int length = selectionModel.getSelectionEnd() - offset;
return new ServerExtractLocalVariableRefactoring(getProject(), psiFile.getVirtualFile(), offset, length);
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class GithubOpenInBrowserAction method makeUrlToOpen.
@Nullable
private static String makeUrlToOpen(@Nullable Editor editor, @NotNull String relativePath, @NotNull String branch, @NotNull String githubRemoteUrl) {
StringBuilder builder = new StringBuilder();
String githubRepoUrl = GithubUrlUtil.makeGithubRepoUrlFromRemoteUrl(githubRemoteUrl);
if (githubRepoUrl == null)
return null;
if (StringUtil.isEmptyOrSpaces(relativePath)) {
builder.append(githubRepoUrl).append("/tree/").append(branch);
} else {
builder.append(githubRepoUrl).append("/blob/").append(branch).append('/').append(relativePath);
}
if (editor != null && editor.getDocument().getLineCount() >= 1) {
// lines are counted internally from 0, but from 1 on github
SelectionModel selectionModel = editor.getSelectionModel();
final int begin = editor.getDocument().getLineNumber(selectionModel.getSelectionStart()) + 1;
final int selectionEnd = selectionModel.getSelectionEnd();
int end = editor.getDocument().getLineNumber(selectionEnd) + 1;
if (editor.getDocument().getLineStartOffset(end - 1) == selectionEnd) {
end -= 1;
}
builder.append("#L").append(begin).append("-L").append(end);
}
return builder.toString();
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class HighlightUsagesHandler method invoke.
public static void invoke(@NotNull final Project project, @NotNull final Editor editor, final PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
final SelectionModel selectionModel = editor.getSelectionModel();
if (file == null && !selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(false);
}
if (file == null || selectionModel.hasSelection()) {
doRangeHighlighting(editor, project);
return;
}
final HighlightUsagesHandlerBase handler = createCustomHandler(editor, file);
if (handler != null) {
final String featureId = handler.getFeatureId();
if (featureId != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(featureId);
}
handler.highlightUsages();
return;
}
DumbService.getInstance(project).withAlternativeResolveEnabled(() -> {
UsageTarget[] usageTargets = getUsageTargets(editor, file);
if (usageTargets == null) {
handleNoUsageTargets(file, editor, selectionModel, project);
return;
}
boolean clearHighlights = isClearHighlights(editor);
for (UsageTarget target : usageTargets) {
target.highlightUsages(file, editor, clearHighlights);
}
});
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class VariableInplaceRenamer method beforeTemplateStart.
@Override
protected void beforeTemplateStart() {
super.beforeTemplateStart();
myLanguage = myScope.getLanguage();
if (shouldCreateSnapshot()) {
final ResolveSnapshotProvider resolveSnapshotProvider = INSTANCE.forLanguage(myLanguage);
mySnapshot = resolveSnapshotProvider != null ? resolveSnapshotProvider.createSnapshot(myScope) : null;
}
final SelectionModel selectionModel = myEditor.getSelectionModel();
mySelectedRange = selectionModel.hasSelection() ? new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) : null;
}
use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.
the class LivePreviewController method performReplaceAll.
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);
}
}
Aggregations