private void setTextFromContext() {
    final Editor editor = myEditor;
    if (editor != null) {
      final SelectionModel selectionModel = editor.getSelectionModel();
      final String selectedText = selectionModel.getSelectedText();
      if (selectedText != null) {
        if (loadConfiguration(selectedText)) {
          return;
        }
        final String text = selectedText.trim();
        setTextForEditor(text.trim(), mySearchCriteriaEdit);
        setTextForEditor(text, myReplaceCriteriaEdit);
        myScopePanel.setScopesFromContext(null);
        final Document document = editor.getDocument();
        final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
        if (file != null) {
          final PsiElement start = file.findElementAt(selectionModel.getSelectionStart());
          final PsiElement end = file.findElementAt(selectionModel.getSelectionEnd() - 1);
          final PsiElement element = (start == null || end == null || start.getContainingFile() != end.getContainingFile())
                                     ? null
                                     : PsiTreeUtil.findCommonParent(start, end);
          final Language language = (element == null) ? file.getLanguage() : element.getLanguage();
          myFileTypeChooser.setSelectedItem(language.getAssociatedFileType(), language, null);
          if (language != file.getLanguage() && !myInjected.isSelected()) {
            myInjected.doClick();
          }
        }
        ApplicationManager.getApplication().invokeLater(() -> startTemplate());
        return;
      }
    }

    final Configuration previousConfiguration = myProject.getUserData(STRUCTURAL_SEARCH_PREVIOUS_CONFIGURATION);
    if (previousConfiguration != null) {
      loadConfiguration(previousConfiguration);
    }
    else {
      final Configuration configuration = ConfigurationManager.getInstance(myProject).getMostRecentConfiguration();
      if (configuration != null) {
        loadConfiguration(configuration);
      }
    }
  }
private void setTextFromContext()