Do not select item by typing dot only for auto-popup completion
This commit is contained in:
@@ -21,6 +21,8 @@ import com.intellij.codeInsight.lookup.Lookup
|
|||||||
import com.intellij.codeInsight.lookup.CharFilter.Result
|
import com.intellij.codeInsight.lookup.CharFilter.Result
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
|
import com.intellij.codeInsight.completion.CompletionService
|
||||||
|
import com.intellij.codeInsight.completion.CompletionProgressIndicator
|
||||||
|
|
||||||
public class KotlinCompletionCharFilter() : CharFilter() {
|
public class KotlinCompletionCharFilter() : CharFilter() {
|
||||||
class object {
|
class object {
|
||||||
@@ -32,6 +34,9 @@ public class KotlinCompletionCharFilter() : CharFilter() {
|
|||||||
override fun acceptChar(c : Char, prefixLength : Int, lookup : Lookup) : Result? {
|
override fun acceptChar(c : Char, prefixLength : Int, lookup : Lookup) : Result? {
|
||||||
if (lookup.getPsiFile() !is JetFile) return null
|
if (lookup.getPsiFile() !is JetFile) return null
|
||||||
if (!lookup.isCompletion()) return null
|
if (!lookup.isCompletion()) return null
|
||||||
|
// it does not work in tests, so we use other way
|
||||||
|
// val isAutopopup = CompletionService.getCompletionService().getCurrentCompletion().isAutopopupCompletion()
|
||||||
|
val isAutopopup = (CompletionService.getCompletionService().getCurrentCompletion() as CompletionProgressIndicator).getParameters().getInvocationCount() == 0
|
||||||
|
|
||||||
if (Character.isJavaIdentifierPart(c) || c == ':' /* used in '::xxx'*/ || c == '@') {
|
if (Character.isJavaIdentifierPart(c) || c == ':' /* used in '::xxx'*/ || c == '@') {
|
||||||
return CharFilter.Result.ADD_TO_PREFIX
|
return CharFilter.Result.ADD_TO_PREFIX
|
||||||
@@ -44,8 +49,7 @@ public class KotlinCompletionCharFilter() : CharFilter() {
|
|||||||
|
|
||||||
return when (c) {
|
return when (c) {
|
||||||
'.' -> {
|
'.' -> {
|
||||||
//TODO: this heuristics better to be only used for auto-popup completion but I see no way to check this
|
if (prefixLength == 0 && isAutopopup && !lookup.isSelectionTouched()) {
|
||||||
if (prefixLength == 0 && !lookup.isSelectionTouched()) {
|
|
||||||
val caret = lookup.getEditor().getCaretModel().getOffset()
|
val caret = lookup.getEditor().getCaretModel().getOffset()
|
||||||
if (caret > 0 && lookup.getEditor().getDocument().getCharsSequence()[caret - 1] == '.') {
|
if (caret > 0 && lookup.getEditor().getDocument().getCharsSequence()[caret - 1] == '.') {
|
||||||
return Result.HIDE_LOOKUP
|
return Result.HIDE_LOOKUP
|
||||||
|
|||||||
Reference in New Issue
Block a user