diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 1eb81503e3c0..f4ab7e6cd966 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -766,7 +766,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } }); - update.addSparedChars(indicator, item, context); + update.addSparedChars(indicator, item, context, completionChar); return context; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java index cc821fb4c868..243ddea9e5ab 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java @@ -387,15 +387,22 @@ public class CompletionLookupArranger extends LookupArranger { public void dispose() { } - public void addSparedChars(CompletionProgressIndicator indicator, LookupElement item, InsertionContext context) { + public void addSparedChars(CompletionProgressIndicator indicator, LookupElement item, InsertionContext context, char completionChar) { String textInserted; if (context.getStartOffset() >= 0 && context.getTailOffset() >= context.getStartOffset()) { textInserted = context.getDocument().getText().substring(context.getStartOffset(), context.getTailOffset()); } else { textInserted = item.getLookupString(); } - textInserted = StringUtil.replace(textInserted, new String[]{" ", "\t", "\n"}, new String[]{"", "", ""}); - int spared = textInserted.length() - indicator.getLookup().itemPattern(item).length(); + String withoutSpaces = StringUtil.replace(textInserted, new String[]{" ", "\t", "\n"}, new String[]{"", "", ""}); + int spared = withoutSpaces.length() - indicator.getLookup().itemPattern(item).length(); + if (completionChar != Lookup.NORMAL_SELECT_CHAR && + completionChar != Lookup.REPLACE_SELECT_CHAR && + completionChar != Lookup.AUTO_INSERT_SELECT_CHAR && + completionChar != Lookup.COMPLETE_STATEMENT_SELECT_CHAR && + withoutSpaces.contains(String.valueOf(completionChar))) { + spared--; + } if (spared > 0) { mySpared += spared; }