mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
select the most relevant item only on explicit user actions (e.g. typing), otherwise try to preserve the lookup selection
This commit is contained in:
+1
-1
@@ -527,7 +527,7 @@ public interface Test {
|
||||
myFixture.completeBasic()
|
||||
while (!lookup.items) {
|
||||
Thread.sleep(10)
|
||||
edt { lookup.refreshUi(false) }
|
||||
edt { lookup.refreshUi(false, false) }
|
||||
}
|
||||
edt { myFixture.type '\t' }
|
||||
myFixture.checkResult 'public interface Test { RuntimeException<caret>x }'
|
||||
|
||||
+1
-1
@@ -475,7 +475,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
LOG.assertTrue(!indicator.isRunning(), "running");
|
||||
LOG.assertTrue(!indicator.isCanceled(), "canceled");
|
||||
|
||||
indicator.getLookup().refreshUi(true);
|
||||
indicator.getLookup().refreshUi(true, false);
|
||||
final AutoCompletionDecision decision = shouldAutoComplete(indicator, items);
|
||||
if (decision == AutoCompletionDecision.SHOW_LOOKUP) {
|
||||
CompletionServiceImpl.setCompletionPhase(new CompletionPhase.ItemsCalculated(indicator));
|
||||
|
||||
+4
-4
@@ -137,7 +137,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup) {
|
||||
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction) {
|
||||
List<LookupElement> items = matchingItems(lookup);
|
||||
Collections.sort(items, new Comparator<LookupElement>() {
|
||||
public int compare(LookupElement o1, LookupElement o2) {
|
||||
@@ -188,7 +188,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
ArrayList<LookupElement> listModel = new ArrayList<LookupElement>(model);
|
||||
|
||||
return new Pair<List<LookupElement>, Integer>(listModel, getItemToSelect(lookup, listModel, inputBySorter));
|
||||
return new Pair<List<LookupElement>, Integer>(listModel, getItemToSelect(lookup, listModel, inputBySorter, onExplicitAction));
|
||||
}
|
||||
|
||||
|
||||
@@ -197,12 +197,12 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
return new CompletionLookupArranger(myParameters, myProcess);
|
||||
}
|
||||
|
||||
private int getItemToSelect(Lookup lookup, List<LookupElement> items, MultiMap<CompletionSorterImpl, LookupElement> inputBySorter) {
|
||||
private int getItemToSelect(Lookup lookup, List<LookupElement> items, MultiMap<CompletionSorterImpl, LookupElement> inputBySorter, boolean onExplicitAction) {
|
||||
if (items.isEmpty() || !lookup.isFocused()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lookup.isSelectionTouched()) {
|
||||
if (lookup.isSelectionTouched() || !onExplicitAction) {
|
||||
LookupElement lastSelection = lookup.getCurrentItem();
|
||||
int old = items.indexOf(lastSelection);
|
||||
if (old >= 0) {
|
||||
|
||||
+2
-2
@@ -353,7 +353,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
}
|
||||
justShown = true;
|
||||
}
|
||||
myLookup.refreshUi(true);
|
||||
myLookup.refreshUi(true, false);
|
||||
hideAutopopupIfMeaningless();
|
||||
if (justShown) {
|
||||
myLookup.ensureSelectionVisible();
|
||||
@@ -518,7 +518,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
|
||||
private boolean hideAutopopupIfMeaningless() {
|
||||
if (!myLookup.isLookupDisposed() && isAutopopupCompletion() && !myLookup.isSelectionTouched() && !myLookup.isCalculating()) {
|
||||
myLookup.refreshUi(true);
|
||||
myLookup.refreshUi(true, false);
|
||||
final List<LookupElement> items = myLookup.getItems();
|
||||
|
||||
for (LookupElement item : items) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class LookupArranger {
|
||||
public void prefixChanged() {
|
||||
}
|
||||
|
||||
public abstract Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup);
|
||||
public abstract Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction);
|
||||
|
||||
public final void clearItems() {
|
||||
prefixChanged();
|
||||
@@ -82,7 +82,7 @@ public abstract class LookupArranger {
|
||||
}
|
||||
|
||||
public static class DefaultArranger extends LookupArranger {
|
||||
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup) {
|
||||
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction) {
|
||||
LinkedHashSet<LookupElement> result = new LinkedHashSet<LookupElement>();
|
||||
List<LookupElement> items = matchingItems(lookup);
|
||||
addPrefixItems(lookup, result, true, items);
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ public abstract class LookupActionHandler extends EditorActionHandler {
|
||||
if (!lookup.isFocused()) {
|
||||
lookup.setFocused(true);
|
||||
lookup.getList().setSelectedIndex(0);
|
||||
lookup.refreshUi(false);
|
||||
lookup.refreshUi(false, true);
|
||||
} else {
|
||||
ListScrollingUtil.moveDown(lookup.getList(), 0);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public abstract class LookupActionHandler extends EditorActionHandler {
|
||||
|
||||
lookup.setFocused(true);
|
||||
lookup.getList().setSelectedIndex(0);
|
||||
lookup.refreshUi(false);
|
||||
lookup.refreshUi(false, true);
|
||||
}
|
||||
ListScrollingUtil.moveUp(lookup.getList(), 0);
|
||||
return true;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class LookupActionsStep extends BaseListPopupStep<LookupElementAction> im
|
||||
} else if (result == LookupElementAction.Result.REFRESH_ITEM) {
|
||||
myLookup.updateLookupWidth(myLookupElement);
|
||||
myLookup.requestResize();
|
||||
myLookup.refreshUi(false);
|
||||
myLookup.refreshUi(false, true);
|
||||
} else if (result instanceof LookupElementAction.Result.ChooseItem) {
|
||||
myLookup.setCurrentItem(((LookupElementAction.Result.ChooseItem)result).item);
|
||||
CommandProcessor.getInstance().executeCommand(myLookup.getEditor().getProject(), new Runnable() {
|
||||
|
||||
@@ -314,7 +314,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
for (final LookupElement item : items) {
|
||||
addItem(item, itemMatcher(item));
|
||||
}
|
||||
refreshUi(true);
|
||||
refreshUi(true, true);
|
||||
}
|
||||
|
||||
public void addItem(LookupElement item, PrefixMatcher matcher) {
|
||||
@@ -387,7 +387,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
myPresentableArranger.prefixChanged();
|
||||
}
|
||||
requestResize();
|
||||
refreshUi(false);
|
||||
refreshUi(false, true);
|
||||
ensureSelectionVisible();
|
||||
}
|
||||
|
||||
@@ -422,14 +422,14 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
}
|
||||
requestResize();
|
||||
if (shouldUpdate) {
|
||||
refreshUi(false);
|
||||
refreshUi(false, true);
|
||||
ensureSelectionVisible();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean updateList() {
|
||||
private boolean updateList(boolean onExplicitAction) {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
}
|
||||
@@ -437,7 +437,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
DefaultListModel listModel = (DefaultListModel)myList.getModel();
|
||||
synchronized (myList) {
|
||||
Pair<List<LookupElement>, Integer> pair = myPresentableArranger.arrangeItems(this);
|
||||
Pair<List<LookupElement>, Integer> pair = myPresentableArranger.arrangeItems(this, onExplicitAction);
|
||||
List<LookupElement> items = pair.first;
|
||||
Integer toSelect = pair.second;
|
||||
if (toSelect == null || toSelect < 0 || items.size() > 0 && toSelect >= items.size()) {
|
||||
@@ -1125,7 +1125,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
refreshUi(true);
|
||||
refreshUi(true, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1236,7 +1236,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
staticDisposeTrace = disposeTrace;
|
||||
}
|
||||
|
||||
public void refreshUi(boolean mayCheckReused) {
|
||||
public void refreshUi(boolean mayCheckReused, boolean onExplicitAction) {
|
||||
final boolean reused = mayCheckReused && checkReused();
|
||||
if (reused) {
|
||||
myAdditionalPrefix = "";
|
||||
@@ -1244,7 +1244,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
|
||||
boolean selectionVisible = isSelectionVisible();
|
||||
|
||||
boolean itemsChanged = updateList();
|
||||
boolean itemsChanged = updateList(onExplicitAction);
|
||||
|
||||
if (isVisible()) {
|
||||
LOG.assertTrue(!ApplicationManager.getApplication().isUnitTestMode());
|
||||
@@ -1300,7 +1300,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
if (!myDisposed) {
|
||||
myAdComponent.addAdvertisement(text);
|
||||
requestResize();
|
||||
refreshUi(false);
|
||||
refreshUi(false, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -203,12 +203,12 @@ public class LookupManagerImpl extends LookupManager {
|
||||
}
|
||||
});
|
||||
|
||||
CamelHumpMatcher matcher = new CamelHumpMatcher(prefix == null ? "" : prefix);
|
||||
CamelHumpMatcher matcher = new CamelHumpMatcher(prefix);
|
||||
if (items.length > 0) {
|
||||
for (final LookupElement item : items) {
|
||||
myActiveLookup.addItem(item, matcher);
|
||||
}
|
||||
myActiveLookup.refreshUi(true);
|
||||
myActiveLookup.refreshUi(true, true);
|
||||
} else {
|
||||
alarm.cancelAllRequests(); // no items -> no doc
|
||||
}
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class ChooseItemReplaceAction extends EditorAction {
|
||||
}
|
||||
|
||||
public static boolean hasTemplatePrefix(LookupImpl lookup, char shortcutChar) {
|
||||
lookup.refreshUi(false); // to bring the list model up to date
|
||||
lookup.refreshUi(false, false); // to bring the list model up to date
|
||||
|
||||
CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
|
||||
if (completion == null || !completion.isAutopopupCompletion()) {
|
||||
|
||||
+2
-2
@@ -127,7 +127,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
|
||||
Editor editor = lookup.getEditor();
|
||||
Project project = editor.getProject();
|
||||
lookup.addLookupListener(new MyLookupAdapter(project, editor, template2Argument));
|
||||
lookup.refreshUi(false);
|
||||
lookup.refreshUi(false, true);
|
||||
lookup.showLookup();
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
|
||||
private static class TemplatesArranger extends LookupArranger {
|
||||
|
||||
@Override
|
||||
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup) {
|
||||
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction) {
|
||||
LinkedHashSet<LookupElement> result = new LinkedHashSet<LookupElement>();
|
||||
List<LookupElement> items = matchingItems(lookup);
|
||||
for (LookupElement item : items) {
|
||||
|
||||
@@ -513,7 +513,7 @@ public class TemplateState implements Disposable {
|
||||
}
|
||||
|
||||
lookup.setAdvertisementText(advertisingText);
|
||||
lookup.refreshUi(true);
|
||||
lookup.refreshUi(true, true);
|
||||
ourLookupShown = true;
|
||||
lookup.addLookupListener(new LookupAdapter() {
|
||||
public void lookupCanceled(LookupEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user