diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/BaseDeclarationInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/BaseDeclarationInsertHandler.kt index 9edda9d0a48..d5cf98dcce3 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/BaseDeclarationInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/BaseDeclarationInsertHandler.kt @@ -26,7 +26,11 @@ open class BaseDeclarationInsertHandler : InsertHandler { override fun handleInsert(context: InsertionContext, item: LookupElement) { val name = (item.`object` as? DeclarationLookupObject)?.name if (name != null && !name.isSpecial) { - context.document.replaceString(context.startOffset, context.tailOffset, name.render()) + val startOffset = context.startOffset + if (startOffset > 0 && context.document.isTextAt(startOffset - 1, "`")) { + context.document.deleteString(startOffset - 1, startOffset) + } + context.document.replaceString(startOffset, context.tailOffset, name.render()) } } } diff --git a/idea/idea-completion/testData/handlers/basic/KT19863.kt b/idea/idea-completion/testData/handlers/basic/KT19863.kt new file mode 100644 index 00000000000..bc994639c22 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/KT19863.kt @@ -0,0 +1,9 @@ +package test + +fun `backticked`() {} + +fun test() { + `ba +} + +// ELEMENT: backticked \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/KT19863.kt.after b/idea/idea-completion/testData/handlers/basic/KT19863.kt.after new file mode 100644 index 00000000000..545ea74c913 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/KT19863.kt.after @@ -0,0 +1,9 @@ +package test + +fun `backticked`() {} + +fun test() { + backticked() +} + +// ELEMENT: backticked \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/KT19864.kt b/idea/idea-completion/testData/handlers/basic/KT19864.kt new file mode 100644 index 00000000000..7f430a0fe2f --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/KT19864.kt @@ -0,0 +1,9 @@ +package test + +fun `backticked~name`() {} + +fun test() { + `ba +} + +// ELEMENT: backticked~name \ No newline at end of file diff --git a/idea/idea-completion/testData/handlers/basic/KT19864.kt.after b/idea/idea-completion/testData/handlers/basic/KT19864.kt.after new file mode 100644 index 00000000000..2ebf81e7840 --- /dev/null +++ b/idea/idea-completion/testData/handlers/basic/KT19864.kt.after @@ -0,0 +1,9 @@ +package test + +fun `backticked~name`() {} + +fun test() { + `backticked~name`() +} + +// ELEMENT: backticked~name \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java index fd40cae2172..d0febeb3afd 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/BasicCompletionHandlerTestGenerated.java @@ -114,6 +114,16 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion runTest("idea/idea-completion/testData/handlers/basic/KT14130.kt"); } + @TestMetadata("KT19863.kt") + public void testKT19863() throws Exception { + runTest("idea/idea-completion/testData/handlers/basic/KT19863.kt"); + } + + @TestMetadata("KT19864.kt") + public void testKT19864() throws Exception { + runTest("idea/idea-completion/testData/handlers/basic/KT19864.kt"); + } + @TestMetadata("KT23627.kt") public void testKT23627() throws Exception { runTest("idea/idea-completion/testData/handlers/basic/KT23627.kt");