YamlScalarTextEvaluator () { return new YamlScalarTextEvaluator<>(this) { @NotNull @Override public List<TextRange> getContentRanges() { final int myStart = getTextRange().getStartOffset(); final List<TextRange> result = new ArrayList<>(); boolean seenText = false; for (ASTNode child = getFirstContentNode(); child != null; child = child.getTreeNext()) { if (child.getElementType() == YAMLTokenTypes.TEXT) { seenText = true; result.add(child.getTextRange().shiftRight(-myStart)); } else if (child.getElementType() == YAMLTokenTypes.EOL) { if (!seenText) { result.add(child.getTextRange().shiftRight(-myStart)); } seenText = false; } } return result; } @NotNull @Override protected String getRangesJoiner(@NotNull CharSequence text, @NotNull List<TextRange> contentRanges, int indexBefore) { if (isNewline(text, contentRanges.get(indexBefore)) || isNewline(text, contentRanges.get(indexBefore + 1))) { return ""; } else { return " "; } } private static boolean isNewline(@NotNull CharSequence text, @NotNull TextRange range) { return range.getLength() == 1 && text.charAt(range.getStartOffset()) == '\n'; } }; }