本文整理汇总了Java中com.intellij.openapi.editor.SelectionModel.getSelectedText方法的典型用法代码示例。如果您正苦于以下问题:Java SelectionModel.getSelectedText方法的具体用法?Java SelectionModel.getSelectedText怎么用?Java SelectionModel.getSelectedText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.SelectionModel
的用法示例。
在下文中一共展示了SelectionModel.getSelectedText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTranslation
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private void getTranslation(AnActionEvent event) {
Editor editor = event.getData(PlatformDataKeys.EDITOR);
if (editor == null) {
return;
}
SelectionModel model = editor.getSelectionModel();
String selectedText = model.getSelectedText();
if (TextUtils.isEmpty(selectedText)) {
selectedText = getCurrentWords(editor);
if (TextUtils.isEmpty(selectedText)) {
return;
}
}
String queryText = strip(addBlanks(selectedText));
new Thread(new RequestRunnable(mTranslator, editor, queryText)).start();
}
示例2: actionPerformed
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor != null) {
final SelectionModel selectionModel = editor.getSelectionModel();
final ImportImpexHttpClient client = new ImportImpexHttpClient();
final String selectedText = selectionModel.getSelectedText();
if (StringUtils.isNotEmpty(selectedText)) {
final HybrisHttpResult hybrisHttpResult = client.importImpex(selectedText);
ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject());
}
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:15,代码来源:ImportImpexAction.java
示例3: actionPerformed
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
public void actionPerformed( AnActionEvent e ) {
Editor editor = ( Editor ) e.getDataContext().getData( "editor" );
SelectionModel selectionModel = editor.getSelectionModel();
if ( selectionModel != null ) {
String selectedText = selectionModel.getSelectedText();
if ( selectedText != null && selectedText.trim().length() > 0 ) {
Project project = ( Project ) e.getDataContext().getData( DataConstants.PROJECT );
String panelid = ( String ) project.getUserData( QuickNotes.KEY_PANELID );
QuickNotesPanel quickNotesPanel = QuickNotesManager.getInstance().getQuickNotesPanel( panelid );
if ( quickNotesPanel != null ) {
FileDocumentManager manager = FileDocumentManager.getInstance();
VirtualFile virtualFile = manager.getFile( editor.getDocument() );
quickNotesPanel.addNewNote( "[File: " + virtualFile.getPath() + "]\n" + selectedText );
}
}
}
}
示例4: getTranslation
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private void getTranslation(AnActionEvent event) {
Editor mEditor = event.getData(PlatformDataKeys.EDITOR);
Project project = event.getData(PlatformDataKeys.PROJECT);
String basePath = project.getBasePath();
if (null == mEditor) {
return;
}
SelectionModel model = mEditor.getSelectionModel();
String selectedText = model.getSelectedText();
if (TextUtils.isEmpty(selectedText)) {
selectedText = getCurrentWords(mEditor);
if (TextUtils.isEmpty(selectedText)) {
return;
}
}
String queryText = strip(addBlanks(selectedText));
new Thread(new RequestRunnable(mEditor, queryText,basePath)).start();
}
示例5: getSelectedText
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Nullable
String getSelectedText(Editor editor) {
SelectionModel selectionModel = editor.getSelectionModel();
if(selectionModel.hasSelection()){
return selectionModel.getSelectedText();
}else {
final ArrayList<TextRange> ranges = new ArrayList<>();
final int offset = editor.getCaretModel().getOffset();
SelectWordUtilCompat.addWordOrLexemeSelection(false, editor, offset, ranges, SelectWordUtilCompat.JAVASCRIPT_IDENTIFIER_PART_CONDITION);
if(ranges.size()>0){
return editor.getDocument().getText(ranges.get(0));
}else {
return null;
}
}
}
示例6: handleNoUsageTargets
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
/**
* {@link com.intellij.codeInsight.highlighting.HighlightUsagesHandler#handleNoUsageTargets(PsiFile,
* Editor, SelectionModel, Project)}
*/
private static void handleNoUsageTargets(PsiFile file, @NotNull Editor editor,
@NotNull Project project) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) {
return;
}
final SelectionModel selectionModel = editor.getSelectionModel();
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
// LOG.assertTrue(selection != null);
if (selection != null) {
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
}
}
searchSelection(editor, project);
selectionModel.removeSelection();
}
}
示例7: 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;
}
示例8: 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));
}
};
}
示例9: handleNoUsageTargets
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private static void handleNoUsageTargets(PsiFile file,
@NotNull Editor editor,
SelectionModel selectionModel,
@NotNull Project project) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) return;
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
LOG.assertTrue(selection != null);
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
}
}
doRangeHighlighting(editor, project);
selectionModel.removeSelection();
}
示例10: actionPerformed
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final MCSettingsProvider settings = MCSettingsProvider.getInstance(e.getProject());
final Editor editor = e.getData(LangDataKeys.EDITOR);
if (editor == null)
return;
final SelectionModel selectionModel = editor.getSelectionModel();
String selectedText;
if (selectionModel.hasSelection()) {
selectedText = selectionModel.getSelectedText();
}
else {
selectionModel.selectLineAtCaret();
if (selectionModel.hasSelection()) {
selectedText = selectionModel.getSelectedText();
selectionModel.removeSelection();
}
else { return; }
}
MayaCommInterface maya = new MayaCommInterface(settings.getHost(), settings.getPort());
maya.connectMayaLog();
maya.sendCodeToMaya(selectedText);
}
示例11: alignText
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
public void alignText(Editor editor) {
String regex = Messages.showInputDialog(editor.getContentComponent(), "Enter regex to align with:", "Front End Alignment", null);
SelectionModel selectionModel = editor.getSelectionModel();
if(selectionModel.getSelectedText() != null) {
Document document = editor.getDocument();
final int startOffset = document.getLineStartOffset(document.getLineNumber(selectionModel.getSelectionStart()));
final int endOffset = document.getLineEndOffset(document.getLineNumber(selectionModel.getSelectionEnd()));
final String text = document.getText(new TextRange(startOffset, endOffset));
final Editor editorArg = editor;
final String newText = (new RegexTextAligner(text, regex)).alignText();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
editorArg.getDocument().replaceString(startOffset, endOffset, newText);
}
});
}
}
示例12: executeMyWriteActionPerCaret
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
protected void executeMyWriteActionPerCaret(Editor editor, Caret caret, DataContext dataContext, T additionalParam) {
final SelectionModel selectionModel = editor.getSelectionModel();
String selectedText = selectionModel.getSelectedText();
if (selectedText == null) {
selectSomethingUnderCaret(editor, dataContext, selectionModel);
selectedText = selectionModel.getSelectedText();
if (selectedText == null) {
return;
}
}
String s = transformSelection(editor, dataContext, selectedText, additionalParam);
s = s.replace("\r\n", "\n");
s = s.replace("\r", "\n");
editor.getDocument().replaceString(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), s);
}
示例13: actionPerformed
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public final void actionPerformed(@NotNull AnActionEvent event) {
final Project project = event.getProject();
if (project == null) {
return;
}
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null) {
return;
}
final Document document = editor.getDocument();
selectText(editor);
SelectionModel selectionModel = editor.getSelectionModel();
boolean word = isWord(document, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
String selectedText = selectionModel.getSelectedText();
if (selectedText == null) {
selectedText = "";
}
String updatedText = updateSelection(selectedText, word);
updateDocument(project, document, selectionModel, updatedText);
}
示例14: handleNoUsageTargets
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private static void handleNoUsageTargets(PsiFile file,
@Nonnull Editor editor,
SelectionModel selectionModel,
@Nonnull Project project) {
if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) return;
selectionModel.selectWordAtCaret(false);
String selection = selectionModel.getSelectedText();
LOG.assertTrue(selection != null);
for (int i = 0; i < selection.length(); i++) {
if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
selectionModel.removeSelection();
}
}
doRangeHighlighting(editor, project);
selectionModel.removeSelection();
}
示例15: getSelectedText
import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
/**
* Returns the selected text if there is any selection. If not return all based on parameter
*
* @param defaultToAll If no selection, then this decides whether to return all text
*/
String getSelectedText(boolean defaultToAll) {
ConsoleView console = this.getConsole();
Editor myEditor = console != null ? (Editor) CommonDataKeys.EDITOR.getData((DataProvider) console) : null;
if (myEditor != null) {
Document document = myEditor.getDocument();
final SelectionModel selectionModel = myEditor.getSelectionModel();
if (selectionModel.hasSelection()) {
return selectionModel.getSelectedText();
} else if (defaultToAll) {
return document.getText();
}
}
return null;
}