public void itemSelected(LookupEvent event) {
          finishCompletionProcess(false);

          LookupElement item = event.getItem();
          if (item == null) return;

          setMergeCommand();

          CodeCompletionHandlerBase.lookupItemSelected(
              CompletionProgressIndicator.this,
              item,
              event.getCompletionChar(),
              myLookup.getItems());
        }
 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();
   }
   String withoutSpaces =
       StringUtil.replace(
           textInserted, new String[] {" ", "\t", "\n"}, new String[] {"", "", ""});
   int spared = withoutSpaces.length() - indicator.getLookup().itemPattern(item).length();
   if (!LookupEvent.isSpecialCompletionChar(completionChar)
       && withoutSpaces.contains(String.valueOf(completionChar))) {
     spared--;
   }
   if (spared > 0) {
     mySpared += spared;
   }
 }
    @Override
    public void itemSelected(LookupEvent event) {
      LookupElement item = event.getItem();
      if (item == null) return;

      char c = event.getCompletionChar();
      if (myCheckCompletionChar && !LookupEvent.isSpecialCompletionChar(c)) {
        return;
      }

      final Project project = myContext.getProject();
      if (project == null) {
        return;
      }

      Runnable runnable =
          () ->
              new WriteCommandAction(project) {
                @Override
                protected void run(@NotNull com.intellij.openapi.application.Result result)
                    throws Throwable {
                  Editor editor = myContext.getEditor();
                  if (editor != null) {
                    TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
                    if (templateState != null) {
                      templateState.considerNextTabOnLookupItemSelected(item);
                    }
                  }
                }
              }.execute();
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
      } else {
        ApplicationManager.getApplication()
            .invokeLater(runnable, ModalityState.current(), project.getDisposed());
      }
    }