本文整理匯總了Java中com.intellij.openapi.editor.SelectionModel.getSelectionStart方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectionModel.getSelectionStart方法的具體用法?Java SelectionModel.getSelectionStart怎麽用?Java SelectionModel.getSelectionStart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.SelectionModel
的用法示例。
在下文中一共展示了SelectionModel.getSelectionStart方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getReplacementRunnable
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
protected Runnable getReplacementRunnable(final Document document, SelectionModel selectionModel) {
final String selectedText = selectionModel.getSelectedText();
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
final Address address = extractLonLatAndGetAddress(selectedText);
Runnable replacementProcess = new Runnable() {
@Override
public void run() {
if (address == null) {
return;
}
document.replaceString(
start,
end,
address.toString());
}
};
return replacementProcess;
}
示例2: checkApplicability
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void checkApplicability(final PsiFile psiFile, final Editor editor) throws IncorrectOperationException {
PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(psiFile, editor);
if (literalExpression != null) {
SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) return;
int start = selectionModel.getSelectionStart();
int end = selectionModel.getSelectionEnd();
TextRange textRange = literalExpression.getTextRange();
if (textRange.contains(start) && textRange.contains(end)) {
mySelectionRange = new TextRange(start, end);
return;
}
}
String message = CodeInsightBundle.message("i18nize.error.message");
throw new IncorrectOperationException(message);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
}
});
}
}
示例6: satisfiedBy
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public boolean satisfiedBy(PsiElement element, @Nullable Editor editor) {
if (editor == null) {
return false;
}
final SelectionModel selectionModel = editor.getSelectionModel();
final Document document = editor.getDocument();
if (selectionModel.hasSelection()) {
final int start = selectionModel.getSelectionStart();
final int end = selectionModel.getSelectionEnd();
if (start < 0 || end < 0 || start > end) {
// shouldn't happen but http://ea.jetbrains.com/browser/ea_problems/50192
return false;
}
final String text = document.getCharsSequence().subSequence(start, end).toString();
return indexOfUnicodeEscape(text, 1) >= 0;
}
else {
final CaretModel caretModel = editor.getCaretModel();
final int lineNumber = document.getLineNumber(caretModel.getOffset());
final String line = document.getText(new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber)));
final int column = caretModel.getLogicalPosition().column;
final int index = indexOfUnicodeEscape(line, column);
return index >= 0 && column >= index;
}
}
示例7: 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;
}
示例8: calculateSelectedTextRectangle
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
private void calculateSelectedTextRectangle() {
SelectionModel selectionModel = myEditor.getSelectionModel();
int selectionStartOffset = selectionModel.getSelectionStart();
int selectionEndOffset = selectionModel.getSelectionEnd();
VisualPosition maxColumnVp = getMaxColumnInsideRange(selectionStartOffset, selectionEndOffset);
Point maxColumnsPoint = myEditor.visualPositionToXY(maxColumnVp);
Point selectionStart = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(selectionStartOffset));
Point selectionEnd = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(selectionEndOffset));
selectionStart = SwingUtilities.convertPoint(myContentComponent, selectionStart, myEditorComponent);
selectionEnd = SwingUtilities.convertPoint(myContentComponent, selectionEnd, myEditorComponent);
maxColumnsPoint = SwingUtilities.convertPoint(myContentComponent, maxColumnsPoint, myEditorComponent);
mySelectionStartY = selectionStart.y;
mySelectionEndY = selectionEnd.y;
myTextRangeMaxColumnX = maxColumnsPoint.x;
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
示例12: 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;
}
示例13: getPsiFileInEditor
import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Nullable
public static PsiFile getPsiFileInEditor(@NotNull final Editor editor, @NotNull final Project project) {
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null) return null;
final Language language = getLanguageInEditor(editor, project);
if (language == null) return file;
if (language == file.getLanguage()) return file;
final SelectionModel selectionModel = editor.getSelectionModel();
int caretOffset = editor.getCaretModel().getOffset();
int mostProbablyCorrectLanguageOffset = caretOffset == selectionModel.getSelectionStart() ||
caretOffset == selectionModel.getSelectionEnd()
? selectionModel.getSelectionStart()
: caretOffset;
return getPsiFileAtOffset(file, mostProbablyCorrectLanguageOffset);
}
示例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);
}
});
}