void (@NotNull String value, @Nullable String prefix) { String text = myTextField.getText(); String suffix = ""; int position = getCaretPosition(); if (myPopup != null) { myPopup.skipCaretEvent = true; } if (position < text.length()) { suffix = text.substring(position); text = text.substring(0, position); } if (prefix == null) { myTextField.setTextIgnoreEvents(text + value + suffix); } else if (StringUtil.startsWithIgnoreCase(value, prefix) || StringUtil.startsWithIgnoreCase(value, "\"" + prefix)) { myTextField.setTextIgnoreEvents(text.substring(0, text.length() - prefix.length()) + value + suffix); } else { myTextField.setTextIgnoreEvents(text + value + suffix); } myTextField.getTextEditor().setCaretPosition(myTextField.getText().length() - suffix.length()); }