private static @NotNull List<@NotNull TextChunk> compactSequentialChunksWithSameAttributes(@NotNull TextChunk @NotNull [] chunks) {
    if (chunks.length == 0) {
      return Collections.emptyList();
    }
    List<TextChunk> result = new ArrayList<>(chunks.length);
    StringBuilder currentText = new StringBuilder();
    AttributesFlyweight currentAttributes = null;
    for (TextChunk chunk : chunks) {
      if (currentAttributes == null) {
        currentAttributes = chunk.myAttributes;
        currentText.append(chunk.myText);
      }
      else if (currentAttributes.equals(chunk.myAttributes)) {
        currentText.append(chunk.myText);
      }
      else {
        result.add(new TextChunk(currentAttributes, currentText.toString()));
        currentAttributes = chunk.myAttributes;
        currentText.setLength(0);
        currentText.append(chunk.myText);
      }
    }
    result.add(new TextChunk(currentAttributes, currentText.toString()));
    return result;
  }
private static @NotNull List<@NotNull TextChunk> compactSequentialChunksWithSameAttributes(@NotNull TextChunk @NotNull [] chunks)