String (@NotNull InsertionContext context, @NotNull String lookupString, final @NotNull String commonPadding_, @NotNull YamlInsertionMarkup markup) { final String COLON = ":"; final String ITEM_MARK = "- "; String sameLineBeforeItem = getHeadStringOnCurrentLine(context, lookupString); final StringBuilder toBeInserted = new StringBuilder(); final StringBuilder toBeRemoved = new StringBuilder(); final StringBuilder totalPadding = new StringBuilder(commonPadding_); if (sameLineBeforeItem.contains(COLON)) { String afterColonBeforeItem = StringUtil.substringAfterLast(sameLineBeforeItem, COLON); if (StringUtil.isEmptyOrSpaces(afterColonBeforeItem)) { toBeRemoved.append(afterColonBeforeItem); } totalPadding.append(markup.getTabSymbol()); toBeInserted.append('\n').append(totalPadding); sameLineBeforeItem = totalPadding.toString(); } if (myNeedsSequenceItem && !sameLineBeforeItem.endsWith(ITEM_MARK)) { toBeInserted.append(ITEM_MARK); totalPadding.append(StringUtil.repeat(" ", ITEM_MARK.length())); } if (toBeInserted.length() != 0) { final Editor editor = context.getEditor(); final int currentOffset = editor.getCaretModel().getOffset(); final int insertedItemStart = currentOffset - lookupString.length(); ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().runUndoTransparentAction(() -> { Document document = editor.getDocument(); document.replaceString(insertedItemStart - toBeRemoved.length(), insertedItemStart, toBeInserted); editor.getCaretModel().moveToOffset(currentOffset + toBeInserted.length() - toBeRemoved.length()); PsiDocumentManager.getInstance(context.getProject()).commitDocument(document); })); } return totalPadding.toString(); }