本文整理匯總了Java中com.intellij.openapi.editor.SelectionModel.getSelectionEnd方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectionModel.getSelectionEnd方法的具體用法?Java SelectionModel.getSelectionEnd怎麽用?Java SelectionModel.getSelectionEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.SelectionModel
的用法示例。
在下文中一共展示了SelectionModel.getSelectionEnd方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getReplacementRunnable
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
@NotNull
protected Runnable getReplacementRunnable(final Document document, SelectionModel selectionModel) {
final String selectedText = selectionModel.getSelectedText();
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final LonLat lonLat = nominatimGeocoder.addressToLonLat(selectedText);
return new Runnable() {
@Override
public void run() {
if (lonLat == null) {
return;
}
document.replaceString(
start,
end,
lonLatRenderer.renderLonLat(lonLat));
}
};
}
示例2: getContents
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@NotNull
public DiffContent[] getContents() {
if (myContents != null) return myContents;
DiffContent clipboardContent = ClipboardVsValueContents.createClipboardContent();
if (clipboardContent == null) clipboardContent = new SimpleContent("");
myContents = new DiffContent[2];
myContents[0] = clipboardContent;
SelectionModel selectionModel = myEditor.getSelectionModel();
if (selectionModel.hasSelection()) {
TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
boolean forceReadOnly = myEditor.isViewer();
myContents[1] = new FragmentContent(DiffContent.fromDocument(getProject(), getDocument()),
range, getProject(), getDocumentFile(getDocument()), forceReadOnly);
}
else {
myContents [1] = DiffContent.fromDocument(getProject(), getDocument());
}
return myContents;
}
示例3: execute
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void execute(final Editor editor, final DataContext dataContext) {
SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
return;
}
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
if (start >= end) {
return;
}
KillRingUtil.copyToKillRing(editor, start, end, false);
if (myRemove) {
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) {
@Override
public void run() {
editor.getDocument().deleteString(start, end);
}
});
}
}
示例4: getNonEmptySelectionRange
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
private static TextRange getNonEmptySelectionRange(Editor editor) {
if (editor != null) {
final SelectionModel model = editor.getSelectionModel();
if (model.hasSelection()) {
final int start = model.getSelectionStart();
final int end = model.getSelectionEnd();
if (start < end) {
return TextRange.create(start, end);
}
}
}
return null;
}
示例5: getSingleLineSelection
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
private static String getSingleLineSelection(@NotNull Editor editor) {
final SelectionModel model = editor.getSelectionModel();
final Document document = editor.getDocument();
if (!model.hasSelection()) {
final int offset = editor.getCaretModel().getOffset();
if (offset <= document.getTextLength()) {
final int lineNumber = document.getLineNumber(offset);
final String line = document.getText().substring(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber)).trim();
if (StringUtil.isNotEmpty(line)) {
return line;
}
}
return null;
}
final int start = model.getSelectionStart();
final int end = model.getSelectionEnd();
if (document.getLineNumber(start) == document.getLineNumber(end)) {
final String selection = document.getText().substring(start, end).trim();
if (StringUtil.isNotEmpty(selection)) {
return selection;
}
}
return null;
}
示例6: getPsiElements
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
protected List<PsiElement> getPsiElements(Class stepClass) {
SelectionModel selectionModel = editor.getSelectionModel();
List<PsiElement> specSteps = new ArrayList<>();
int currentOffset = selectionModel.getSelectionStart();
while (selectionModel.getSelectionEnd() >= currentOffset) {
try {
if (psiFile.getText().charAt(currentOffset++) == '\n') continue;
PsiElement step = getStep(psiFile.findElementAt(currentOffset), stepClass);
if (step == null) return new ArrayList<>();
specSteps.add(step);
currentOffset += step.getText().length();
} catch (Exception ignored) {
}
}
return specSteps;
}
示例7: wrap
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
/**
* Wraps selection.
*
* @param editor Current editor.
*/
private void wrap(@NotNull TextEditor editor) {
final Document document = editor.getEditor().getDocument();
final SelectionModel selectionModel = editor.getEditor().getSelectionModel();
final CaretModel caretModel = editor.getEditor().getCaretModel();
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final String text = StringUtil.notNullize(selectionModel.getSelectedText());
String newText = getLeftText() + text + getRightText();
int newStart = start + getLeftText().length();
int newEnd = StringUtil.isEmpty(text) ? newStart : end + getLeftText().length();
document.replaceString(start, end, newText);
selectionModel.setSelection(newStart, newEnd);
caretModel.moveToOffset(newEnd);
}
示例8: unwrap
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
/**
* Unwraps selection.
*
* @param editor Current editor.
* @param matched Matched PSI element.
*/
private void unwrap(@NotNull final TextEditor editor, @NotNull final PsiElement matched) {
final Document document = editor.getEditor().getDocument();
final SelectionModel selectionModel = editor.getEditor().getSelectionModel();
final CaretModel caretModel = editor.getEditor().getCaretModel();
final int start = matched.getTextRange().getStartOffset();
final int end = matched.getTextRange().getEndOffset();
final String text = StringUtil.notNullize(matched.getText());
String newText = StringUtil.trimEnd(StringUtil.trimStart(text, getLeftText()), getRightText());
int newStart = selectionModel.getSelectionStart() - getLeftText().length();
int newEnd = selectionModel.getSelectionEnd() - getLeftText().length();
document.replaceString(start, end, newText);
selectionModel.setSelection(newStart, newEnd);
caretModel.moveToOffset(newEnd);
}
示例9: getContents
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@NotNull
public DiffContent[] getContents() {
if (myContents != null) return myContents;
DiffContent clipboardContent = ClipboardVsValueContents.createClipboardContent();
if (clipboardContent == null) clipboardContent = new SimpleContent("");
myContents = new DiffContent[2];
myContents[0] = clipboardContent;
SelectionModel selectionModel = myEditor.getSelectionModel();
if (selectionModel.hasSelection()) {
TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
myContents[1] = new FragmentContent(DiffContent.fromDocument(getProject(), getDocument()),
range, getProject(), getDocumentFile(getDocument()));
}
else {
myContents [1] = DiffContent.fromDocument(getProject(), getDocument());
}
return myContents;
}
示例10: execute
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void execute(Editor editor, DataContext dataContext) {
if (!(editor instanceof EditorEx)) {
return;
}
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
return;
}
EditorEx editorEx = (EditorEx)editor;
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final CaretModel caretModel = editor.getCaretModel();
boolean moveToEnd = caretModel.getOffset() == start;
editorEx.setStickySelection(false);
editorEx.setStickySelection(true);
if (moveToEnd) {
caretModel.moveToOffset(end);
}
else {
caretModel.moveToOffset(start);
}
}
示例11: makeUrlToOpen
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
private static String makeUrlToOpen(@NotNull AnActionEvent e, @NotNull String relativePath, @NotNull String branch,
@NotNull String githubRemoteUrl) {
final StringBuilder builder = new StringBuilder();
final String githubRepoUrl = GithubUrlUtil.makeGithubRepoUrlFromRemoteUrl(githubRemoteUrl);
if (githubRepoUrl == null) {
return null;
}
builder.append(githubRepoUrl).append("/blob/").append(branch).append(relativePath);
final Editor editor = e.getData(PlatformDataKeys.EDITOR);
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('-').append(end);
}
return builder.toString();
}
示例12: getLanguageInEditor
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
public static Language getLanguageInEditor(@NotNull final Editor editor, @NotNull final Project project) {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return null;
final SelectionModel selectionModel = editor.getSelectionModel();
int caretOffset = editor.getCaretModel().getOffset();
int mostProbablyCorrectLanguageOffset = caretOffset == selectionModel.getSelectionStart() ||
caretOffset == selectionModel.getSelectionEnd()
? selectionModel.getSelectionStart()
: caretOffset;
PsiElement elt = getElementAtOffset(file, mostProbablyCorrectLanguageOffset);
Language lang = findLanguageFromElement(elt);
if (selectionModel.hasSelection()) {
final Language rangeLanguage = evaluateLanguageInRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), file);
if (rangeLanguage == null) return file.getLanguage();
lang = rangeLanguage;
}
return narrowLanguage(lang, file.getLanguage());
}
示例13: getInjectedEditorForInjectedFile
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@NotNull
public static Editor getInjectedEditorForInjectedFile(@NotNull Editor hostEditor, @Nullable final PsiFile injectedFile) {
if (injectedFile == null || hostEditor instanceof EditorWindow || hostEditor.isDisposed()) return hostEditor;
Project project = hostEditor.getProject();
if (project == null) project = injectedFile.getProject();
Document document = PsiDocumentManager.getInstance(project).getDocument(injectedFile);
if (!(document instanceof DocumentWindowImpl)) return hostEditor;
DocumentWindowImpl documentWindow = (DocumentWindowImpl)document;
SelectionModel selectionModel = hostEditor.getSelectionModel();
if (selectionModel.hasSelection()) {
int selstart = selectionModel.getSelectionStart();
int selend = selectionModel.getSelectionEnd();
if (!documentWindow.containsRange(selstart, selend)) {
// selection spreads out the injected editor range
return hostEditor;
}
}
if (!documentWindow.isValid()) return hostEditor; // since the moment we got hold of injectedFile and this moment call, document may have been dirtied
return EditorWindow.create(documentWindow, (EditorImpl)hostEditor, injectedFile);
}
示例14: replaceWordSimple
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private void replaceWordSimple(final CharSequence selectedValue)
{
final Project project = editor.getProject();
final Document document = editor.getDocument();
final SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(true);
}
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
Runnable runnable = new Runnable()
{
@Override
public void run()
{
document.replaceString(start, end, selectedValue);
}
};
//Making the replacement
WriteCommandAction.runWriteCommandAction(project, runnable);
selectionModel.removeSelection();
}
示例15: updateDocument
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private void updateDocument(final Project project, final Document document, final SelectionModel selectionModel, final String updatedText) {
final Runnable readRunner = new Runnable() {
@Override
public void run() {
int start = selectionModel.getSelectionStart();
int end = selectionModel.getSelectionEnd();
document.replaceString(start, end, updatedText);
}
};
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(readRunner);
}
}, getName(), null);
}
});
}