use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method assertPreferredCompletionItems.
@Override
public void assertPreferredCompletionItems(final int selected, @NotNull final String... expected) {
final LookupImpl lookup = getLookup();
assertNotNull("No lookup is shown", lookup);
final JList list = lookup.getList();
List<String> strings = getLookupElementStrings();
assertNotNull(strings);
final List<String> actual = strings.subList(0, Math.min(expected.length, strings.size()));
if (!actual.equals(Arrays.asList(expected))) {
UsefulTestCase.assertOrderedEquals(DumpLookupElementWeights.getLookupElementWeights(lookup, false), expected);
}
if (selected != list.getSelectedIndex()) {
//noinspection UseOfSystemOutOrSystemErr
System.out.println(DumpLookupElementWeights.getLookupElementWeights(lookup, false));
}
assertEquals(selected, list.getSelectedIndex());
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class InplaceRefactoring method restoreOldCaretPositionAndSelection.
private void restoreOldCaretPositionAndSelection(final int offset) {
//move to old offset
Runnable runnable = () -> {
myEditor.getCaretModel().moveToOffset(restoreCaretOffset(offset));
restoreSelection();
};
final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
if (lookup != null && lookup.getLookupStart() <= (restoreCaretOffset(offset))) {
lookup.setFocusDegree(LookupImpl.FocusDegree.UNFOCUSED);
lookup.performGuardedChange(runnable);
} else {
runnable.run();
}
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class CodeCompletionHandlerBase method obtainLookup.
@NotNull
private LookupImpl obtainLookup(Editor editor, Project project) {
CompletionAssertions.checkEditorValid(editor);
LookupImpl existing = (LookupImpl) LookupManager.getActiveLookup(editor);
if (existing != null && existing.isCompletion()) {
existing.markReused();
if (!autopopup) {
existing.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
}
return existing;
}
LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new LookupArranger.DefaultArranger());
if (editor.isOneLineMode()) {
lookup.setCancelOnClickOutside(true);
lookup.setCancelOnOtherWindowOpen(true);
}
lookup.setFocusDegree(autopopup ? LookupImpl.FocusDegree.UNFOCUSED : LookupImpl.FocusDegree.FOCUSED);
return lookup;
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class ListTemplatesHandler method showTemplatesLookup.
public static void showTemplatesLookup(final Project project, final Editor editor, Map<TemplateImpl, String> template2Argument) {
final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new LookupArranger.DefaultArranger());
for (TemplateImpl template : template2Argument.keySet()) {
String prefix = computePrefix(template, template2Argument.get(template));
lookup.addItem(createTemplateElement(template), new PlainPrefixMatcher(prefix));
}
showLookup(lookup, template2Argument);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class ConsoleExecuteAction method update.
@Override
public final void update(@NotNull AnActionEvent e) {
EditorEx editor = myConsoleView.getConsoleEditor();
boolean enabled = !editor.isRendererMode() && isEnabled() && (myExecuteActionHandler.isEmptyCommandExecutionAllowed() || !StringUtil.isEmptyOrSpaces(editor.getDocument().getCharsSequence()));
if (enabled) {
Lookup lookup = LookupManager.getActiveLookup(editor);
// we should check getCurrentItem() also - fast typing could produce outdated lookup, such lookup reports isCompletion() true
enabled = lookup == null || !lookup.isCompletion() || lookup.getCurrentItem() == null || (lookup instanceof LookupImpl && ((LookupImpl) lookup).getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED);
}
e.getPresentation().setEnabled(enabled);
}
Aggregations