TemplateActionContext (@NotNull PsiFile psiFile, @NotNull Editor editor) { SelectionModel selectionModel = editor.getSelectionModel(); int start = selectionModel.getSelectionStart(); int end = selectionModel.getSelectionEnd(); PsiElement startElement = psiFile.findElementAt(start); if (startElement instanceof PsiWhiteSpace) { start = Math.min(startElement.getTextRange().getEndOffset(), end); } PsiElement endElement = psiFile.findElementAt(end); if (endElement != startElement && endElement instanceof PsiWhiteSpace) { end = Math.max(start, endElement.getTextRange().getStartOffset()); } return create(psiFile, editor, start, end, true); }