void beforeCommandFinished() {
      CaretAction action = caret -> {
        Couple<RangeMarker> markers = getMarkers(caret);
        final Document document = myEditor.getDocument();
        if (markers == null
            || !markers.first.isValid()
            || !markers.second.isValid()
            || getNameToReplace(document, markers) == null) {
          return;
        }

        final Runnable apply = () -> {
          final String name = getNameToReplace(document, markers);
          if (name != null) {
            final RangeMarker support = markers.second;
            document.replaceString(support.getStartOffset(), support.getEndOffset(), name);
          }
        };
        ApplicationManager.getApplication().runWriteAction(() -> {
          final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
          if (lookup != null) {
            lookup.performGuardedChange(apply);
          }
          else {
            apply.run();
          }
        });
      };
      myApplying = true;
      try {
        if (myEditor.getCaretModel().isIteratingOverCarets()) {
          action.perform(myEditor.getCaretModel().getCurrentCaret());
        }
        else {
          myEditor.getCaretModel().runForEachCaret(action);
        }
      }
      finally {
        myApplying = false;
      }
    }
void beforeCommandFinished()