PsiLanguageInjectionHost (@NotNull String text) { String original = getNode().getText(); int commonPrefixLength = StringUtil.commonPrefixLength(original, text); int commonSuffixLength = StringUtil.commonSuffixLength(original, text); int indent = locateIndent(); ASTNode scalarEol = getNode().findChildByType(YAMLTokenTypes.SCALAR_EOL); if (scalarEol == null) { // a very strange situation return super.updateText(text); } int eolOffsetInParent = scalarEol.getStartOffsetInParent(); int startContent = eolOffsetInParent + indent + 1; if (startContent > commonPrefixLength) { // a very strange situation return super.updateText(text); } String originalRowPrefix = original.substring(startContent, commonPrefixLength); String indentString = StringUtil.repeatSymbol(' ', indent); String prefix = originalRowPrefix.replaceAll("\n" + indentString, "\n"); String suffix = text.substring(text.length() - commonSuffixLength).replaceAll("\n" + indentString, "\n"); String result = prefix + text.substring(commonPrefixLength, text.length() - commonSuffixLength) + suffix; return super.updateText(result); }