From d2aa1f7e3929e685df6c27ef788e0df42367018d Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 28 Mar 2017 17:49:58 +0200 Subject: [PATCH] advertise replacement with Tab in the bottom of lookup (IDEA-88157, IDEA-124699) --- .../CompletionProgressIndicator.java | 78 +++++++++++++------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 393305d6c186..180147cd2228 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -200,32 +200,12 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement } void duringCompletion(CompletionInitializationContext initContext) { - if (isAutopopupCompletion()) { - if (shouldPreselectFirstSuggestion(myParameters)) { - if (!CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) { - myLookup.setFocusDegree(LookupImpl.FocusDegree.SEMI_FOCUSED); - if (FeatureUsageTracker.getInstance().isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_CONTROL_DOT, getProject())) { - String dotShortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_DOT); - if (StringUtil.isNotEmpty(dotShortcut)) { - addAdvertisement("Press " + dotShortcut + " to choose the selected (or first) suggestion and insert a dot afterwards", null); - } - } - } else { - myLookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED); - } - } - if (!myEditor.isOneLineMode() && - FeatureUsageTracker.getInstance() - .isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ARROWS, getProject())) { - String downShortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_LOOKUP_DOWN); - String upShortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_LOOKUP_UP); - if (StringUtil.isNotEmpty(downShortcut) && StringUtil.isNotEmpty(upShortcut)) { - addAdvertisement(downShortcut + " and " + upShortcut + " will move caret down and up in the editor", null); - } - } - } else if (DumbService.isDumb(getProject())) { - addAdvertisement("The results might be incomplete while indexing is in progress", MessageType.WARNING.getPopupBackground()); + if (isAutopopupCompletion() && shouldPreselectFirstSuggestion(myParameters)) { + myLookup.setFocusDegree(CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS + ? LookupImpl.FocusDegree.FOCUSED + : LookupImpl.FocusDegree.SEMI_FOCUSED); } + addDefaultAdvertisements(); ProgressManager.checkCanceled(); @@ -262,6 +242,54 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement myHostOffsets = new OffsetsInFile(initContext.getFile(), initContext.getOffsetMap()).toTopLevelFile(); } } + + + private void addDefaultAdvertisements() { + if (DumbService.isDumb(getProject())) { + addAdvertisement("The results might be incomplete while indexing is in progress", MessageType.WARNING.getPopupBackground()); + return; + } + + advertiseTabReplacement(); + if (isAutopopupCompletion()) { + if (shouldPreselectFirstSuggestion(myParameters) && !CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) { + advertiseCtrlDot(); + } + advertiseCtrlArrows(); + } + } + + private void advertiseTabReplacement() { + if (CompletionUtil.shouldShowFeature(myParameters, CodeCompletionFeatures.EDITING_COMPLETION_REPLACE) && + myOffsetMap.getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET) != myOffsetMap.getOffset(CompletionInitializationContext.SELECTION_END_OFFSET)) { + String shortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE); + if (StringUtil.isNotEmpty(shortcut)) { + addAdvertisement("Use " + shortcut + " to overwrite the current identifier with the chosen variant", null); + } + } + } + + private void advertiseCtrlDot() { + if (FeatureUsageTracker + .getInstance().isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_CONTROL_DOT, getProject())) { + String dotShortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_DOT); + if (StringUtil.isNotEmpty(dotShortcut)) { + addAdvertisement("Press " + dotShortcut + " to choose the selected (or first) suggestion and insert a dot afterwards", null); + } + } + } + + private void advertiseCtrlArrows() { + if (!myEditor.isOneLineMode() && + FeatureUsageTracker.getInstance() + .isToBeAdvertisedInLookup(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ARROWS, getProject())) { + String downShortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_LOOKUP_DOWN); + String upShortcut = CompletionContributor.getActionShortcut(IdeActions.ACTION_LOOKUP_UP); + if (StringUtil.isNotEmpty(downShortcut) && StringUtil.isNotEmpty(upShortcut)) { + addAdvertisement(downShortcut + " and " + upShortcut + " will move caret down and up in the editor", null); + } + } + } @NotNull CompletionSorterImpl getSorter(LookupElement element) {