boolean (@NotNull Project project, Editor editor, PsiFile file) { if (!(file instanceof ShFile)) return false; SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasSelection()) { String selectedText = selectionModel.getSelectedText(); if (StringUtil.isEmptyOrSpaces(selectedText)) return false; if (selectedText.trim().contains("\n")) return false; } Caret caret = editor.getCaretModel().getPrimaryCaret(); int offset = caret.getOffset(); PsiElement at = file.findElementAt(offset); if (at == null) return false; //noinspection RedundantIfStatement if (at instanceof LeafPsiElement && at.getParent() instanceof ShFile) return false; return true; }