autopopup after . is also an autopopup and should track editor events

This commit is contained in:
peter
2011-02-04 21:40:26 +01:00
parent f5530cba10
commit a92e8b744a
3 changed files with 47 additions and 28 deletions

View File

@@ -444,4 +444,21 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase {
assert !lookup
}
public void testResumeAfterBackspace() {
myFixture.configureByText("a.java", """
class A {
Object foo() { this<caret> }
}
""")
type '.'
assert lookup
type 'a'
assert !lookup
type '\b'
assert !lookup
type 'c'
assert lookup
}
}

View File

@@ -16,9 +16,7 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.completion.CodeCompletionHandlerBase;
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
import com.intellij.codeInsight.hint.ShowParameterInfoHandler;
@@ -101,7 +99,7 @@ public class AutoPopupController implements Disposable {
if (!file.isValid()) return;
if (condition != null && !condition.value(file)) return;
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(myProject, editor, file);
CompletionAutoPopupHandler.invokeAutoPopupCompletion(myProject, editor);
}
};

View File

@@ -112,37 +112,41 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
if (ApplicationManager.getApplication().isWriteAccessAllowed()) return; //it will fail anyway
if (DumbService.getInstance(project).isDumb()) return;
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(project, editor);
final AutoPopupState state = new AutoPopupState(project, editor);
editor.putUserData(STATE_KEY, state);
final Lookup lookup = LookupManager.getActiveLookup(editor);
if (lookup != null) {
lookup.addLookupListener(new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (state != null) {
state.stopAutoPopup();
}
}
@Override
public void lookupCanceled(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (event.isCanceledExplicitly() && state != null) {
state.stopAutoPopup();
}
}
});
}
invokeAutoPopupCompletion(project, editor);
}
};
AutoPopupController.getInstance(project).invokeAutoPopupRunnable(request, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
return Result.STOP;
}
public static void invokeAutoPopupCompletion(Project project, final Editor editor) {
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true).invoke(project, editor);
final AutoPopupState state = new AutoPopupState(project, editor);
editor.putUserData(STATE_KEY, state);
final Lookup lookup = LookupManager.getActiveLookup(editor);
if (lookup != null) {
lookup.addLookupListener(new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (state != null) {
state.stopAutoPopup();
}
}
@Override
public void lookupCanceled(LookupEvent event) {
final AutoPopupState state = getAutoPopupState(editor);
if (event.isCanceledExplicitly() && state != null) {
state.stopAutoPopup();
}
}
});
}
}
@Nullable
private static AutoPopupState getAutoPopupState(Editor editor) {
return editor.getUserData(STATE_KEY);