public void assertSelection(@Nullable String expected) { final String selected = myFixture.getEditor().getSelectionModel().getSelectedText(); assertEquals(expected, selected); }
/** * Handles an action of adding new template. * Ignores action if selected file is not a {@link IgnoreFile} instance, otherwise shows GeneratorDialog. * * @param e action event */ @Override public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final PsiFile file = e.getData(CommonDataKeys.PSI_FILE); if (project == null || !(file instanceof IgnoreFile)) { return; } String content = file.getText(); Document document = file.getViewProvider().getDocument(); if (document != null) { Editor[] editors = EditorFactory.getInstance().getEditors(document); if (editors.length > 0) { String selectedText = editors[0].getSelectionModel().getSelectedText(); if (!StringUtil.isEmpty(selectedText)) { content = selectedText; } } } new UserTemplateDialog(project, content).show(); }
@Override public void actionPerformed(AnActionEvent event) { super.actionPerformed(event); final Editor editor = event.getRequiredData(CommonDataKeys.EDITOR); String selectText = editor.getSelectionModel().getSelectedText(); if (selectText != null && selectText.length() > 40) { selectText = selectText.substring(0, 40); } new GlobalSearchDialog(selectText, this).setVisible(true); }
String translationText = editor.getSelectionModel().getSelectedText();
/** * {@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(); } }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element == null) { return; } Editor editor = PsiUtilBase.findEditor(element); if (editor == null) { return; } TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRange(); editor.getSelectionModel().setSelection(textRange.getStartOffset(), textRange.getEndOffset()); String wordWithQuotes = editor.getSelectionModel().getSelectedText(); String word = EndpointUtilities.removeBeginningAndEndingQuotes(wordWithQuotes); if (word == null || StringUtil.isEmpty(word)) { return; } String variant = "\"" + getNameSuggestions(word) + "\""; LookupManager lookupManager = LookupManager.getInstance(project); lookupManager.showLookup(editor, LookupElementBuilder.create(variant)); }
/** * Provides a replacement API method name that matches the {@link * MethodNameInspection.API_NAME_PATTERN}. * * @param project {@link com.intellij.openapi.project.Project} * @param descriptor problem reported by the tool which provided this quick fix action */ @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement element = descriptor.getPsiElement(); if (element == null) { return; } Editor editor = PsiUtilBase.findEditor(element); if (editor == null) { return; } TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRange(); editor.getSelectionModel().setSelection(textRange.getStartOffset(), textRange.getEndOffset()); String wordWithQuotes = editor.getSelectionModel().getSelectedText(); String word = EndpointUtilities.removeBeginningAndEndingQuotes(wordWithQuotes); if (word == null || StringUtil.isEmpty(word)) { return; } String variant = "\"" + getMethodNameSuggestions(word) + "\""; LookupManager lookupManager = LookupManager.getInstance(project); lookupManager.showLookup(editor, LookupElementBuilder.create(variant)); }
@Override public void actionPerformed(@NotNull final AnActionEvent e) { final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); if (editor != null) { final SelectionModel selectionModel = editor.getSelectionModel(); String content = selectionModel.getSelectedText(); if (content == null || content.trim().isEmpty()) { content = editor.getDocument().getText(); } final HybrisConsolePanelView consolePanelView = ServiceManager.getService( e.getProject(), HybrisConsolePanelView.class ); final HybrisConsolePanel consolePanel = consolePanelView.getConsolePanel(); final HybrisConsole console = consolePanel.findConsole(getConsoleName()); if (console == null) { LOG.warn("unable to find console "+getConsoleName()); return; } consolePanel.setActiveConsole(console); consolePanel.sendTextToConsole(console, content); doExecute(consolePanel); ToolWindow toolWindow = ToolWindowManager.getInstance(e.getProject()).getToolWindow( HybrisConsoleToolWindowFactory.ID); toolWindow.activate(null); } }
final String text = selectionModel.getSelectedText(); if (text == null) { return;
final SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasSelection()) { final String selectedText = selectionModel.getSelectedText(); if (selectedText != null) { MathematicaPsiElementFactory factory = new MathematicaPsiElementFactory(project);
final String ruleText = selectionModel.getSelectedText();