No repeating of completion auto-popup after Esc in all positions

This commit is contained in:
Valentin Kipyatkov
2015-08-20 16:23:35 +03:00
parent a015c44a60
commit 9900506254
2 changed files with 13 additions and 9 deletions
@@ -158,11 +158,11 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
}
public fun shouldDisableAutoPopup(): Boolean {
if (completionKind == CompletionKind.PARAMETER_NAME || completionKind == CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME) {
if (LookupCancelWatcher.getInstance(project).wasAutoPopupRecentlyCancelled(parameters.editor, position.startOffset)) {
return true
}
if (LookupCancelWatcher.getInstance(project).wasAutoPopupRecentlyCancelled(parameters.editor, position.startOffset)) {
return true
}
if (completionKind == CompletionKind.PARAMETER_NAME || completionKind == CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME) {
if (!shouldCompleteParameterNameAndType()) {
return true
}
@@ -174,6 +174,13 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
override fun doComplete() {
assert(parameters.getCompletionType() == CompletionType.BASIC)
if (parameters.isAutoPopup) {
collector.addLookupElementPostProcessor { lookupElement ->
lookupElement.putUserData(LookupCancelWatcher.AUTO_POPUP_AT, position.startOffset)
lookupElement
}
}
// if we are typing parameter name, restart completion each time we type an upper case letter because new suggestions will appear (previous words can be used as user prefix)
if (parameterNameAndTypeCompletion != null) {
val prefixPattern = StandardPatterns.string().with(object : PatternCondition<String>("Prefix ends with uppercase letter") {
@@ -184,9 +191,6 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
collector.addLookupElementPostProcessor { lookupElement ->
lookupElement.putUserData(KotlinCompletionCharFilter.SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING, Unit)
lookupElement.putUserData(KotlinCompletionCharFilter.HIDE_LOOKUP_ON_COLON, Unit)
if (parameters.isAutoPopup) {
lookupElement.putUserData(LookupCancelWatcher.DO_NOT_REPEAT_AUTO_POPUP_AT, position.startOffset)
}
lookupElement
}
@@ -69,7 +69,7 @@ class LookupCancelWatcher(project: Project) : AbstractProjectComponent(project)
companion object {
fun getInstance(project: Project): LookupCancelWatcher = project.getComponent(javaClass<LookupCancelWatcher>())!!
val DO_NOT_REPEAT_AUTO_POPUP_AT = Key<Int>("LookupCancelWatcher.DO_NOT_REPEAT_AUTO_POPUP_AT")
val AUTO_POPUP_AT = Key<Int>("LookupCancelWatcher.DO_NOT_REPEAT_AUTO_POPUP_AT")
}
fun wasAutoPopupRecentlyCancelled(editor: Editor, offset: Int): Boolean {
@@ -80,7 +80,7 @@ class LookupCancelWatcher(project: Project) : AbstractProjectComponent(project)
override fun lookupCanceled(event: LookupEvent) {
val lookup = event.lookup
if (event.isCanceledExplicitly && lookup.isCompletion) {
val offset = lookup.currentItem?.getUserData(DO_NOT_REPEAT_AUTO_POPUP_AT)
val offset = lookup.currentItem?.getUserData(AUTO_POPUP_AT)
if (offset != null) {
lastReminiscence?.dispose()
lastReminiscence = Reminiscence(lookup.editor, offset)