|
11 | 11 | import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction; |
12 | 12 | import com.intellij.ide.impl.DataManagerImpl; |
13 | 13 | import com.intellij.lang.jsgraphql.endpoint.JSGraphQLEndpointTokenTypes; |
| 14 | +import com.intellij.lang.jsgraphql.endpoint.doc.psi.JSGraphQLEndpointDocPsiUtil; |
14 | 15 | import com.intellij.lang.jsgraphql.endpoint.psi.*; |
15 | 16 | import com.intellij.openapi.actionSystem.ActionManager; |
16 | 17 | import com.intellij.openapi.actionSystem.ActionPlaces; |
|
20 | 21 | import com.intellij.openapi.editor.Editor; |
21 | 22 | import com.intellij.openapi.project.Project; |
22 | 23 | import com.intellij.openapi.util.Ref; |
23 | | -import com.intellij.openapi.util.TextRange; |
| 24 | +import com.intellij.psi.PsiComment; |
24 | 25 | import com.intellij.psi.PsiDocumentManager; |
25 | 26 | import com.intellij.psi.PsiElement; |
26 | 27 | import com.intellij.psi.PsiReference; |
@@ -77,8 +78,17 @@ public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement |
77 | 78 | indent = true; |
78 | 79 | } |
79 | 80 | final Document document = editor.getDocument(); |
80 | | - final TextRange definitionTextRange = definition.getTextRange(); |
81 | | - final int insertOffset = insertBefore ? definitionTextRange.getStartOffset() : definitionTextRange.getEndOffset(); |
| 81 | + final int insertOffset; |
| 82 | + if(insertBefore) { |
| 83 | + final PsiComment documentationStartElement = JSGraphQLEndpointDocPsiUtil.getDocumentationStartElement(definition); |
| 84 | + if(documentationStartElement != null) { |
| 85 | + insertOffset = documentationStartElement.getTextRange().getStartOffset(); |
| 86 | + } else { |
| 87 | + insertOffset = definition.getTextRange().getStartOffset(); |
| 88 | + } |
| 89 | + } else { |
| 90 | + insertOffset = definition.getTextRange().getEndOffset(); |
| 91 | + } |
82 | 92 | document.insertString(insertOffset, definitionText); |
83 | 93 | if (caretOffsetAfterInsert.get() != null) { |
84 | 94 | // move caret to new position |
|
0 commit comments