File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import com.intellij.codeInsight.lookup.AutoCompletionPolicy
2121import com.intellij.codeInsight.lookup.LookupElement
2222import com.intellij.codeInsight.lookup.LookupElementBuilder
2323import com.intellij.psi.PsiElement
24+ import com.intellij.psi.util.prevLeafs
2425
2526class PercentDirectiveHandler (
2627 originalFile : PsiElement ,
@@ -32,6 +33,11 @@ class PercentDirectiveHandler(
3233 element,
3334 result,
3435 ) { bind ->
36+ val beforeTextChars =
37+ this .element.prevLeafs
38+ .takeWhile { prev -> prev.text != " %" }
39+ .toList()
40+ .size
3541 listOf (
3642 " if" ,
3743 " elseif" ,
@@ -46,7 +52,12 @@ class PercentDirectiveHandler(
4652 }.map {
4753 LookupElementBuilder
4854 .create(it)
49- .withAutoCompletionPolicy(AutoCompletionPolicy .ALWAYS_AUTOCOMPLETE )
55+ .withInsertHandler { context, _ ->
56+ val start = context.startOffset - beforeTextChars
57+ val tail = context.tailOffset
58+ context.document.replaceString(start, tail, it)
59+ context.editor.caretModel.moveToOffset(start + it.length)
60+ }.withAutoCompletionPolicy(AutoCompletionPolicy .ALWAYS_AUTOCOMPLETE )
5061 }
5162 }
5263
You can’t perform that action at this time.
0 commit comments