int (final TextRange elementRange, final int shift) { final StringBuilder buffer = new StringBuilder(); StringBuilder afterWhiteSpace = new StringBuilder(); int whiteSpaceLength = 0; boolean insideWhiteSpace = true; int line = 0; for (int i = elementRange.getStartOffset(); i < elementRange.getEndOffset(); i++) { final char c = myDocument.getCharsSequence().charAt(i); switch (c) { case '\n' -> { if (line > 0) { createWhiteSpace(whiteSpaceLength + shift, buffer); } else { createWhiteSpace(whiteSpaceLength, buffer); } buffer.append(afterWhiteSpace); insideWhiteSpace = true; whiteSpaceLength = 0; afterWhiteSpace = new StringBuilder(); buffer.append(c); line++; } case ' ' -> { if (insideWhiteSpace) { whiteSpaceLength += 1; } else { afterWhiteSpace.append(c); } } case '\t' -> { if (insideWhiteSpace) { whiteSpaceLength += getIndentOptions().TAB_SIZE; } else { afterWhiteSpace.append(c); } } default -> { insideWhiteSpace = false; afterWhiteSpace.append(c); } } } if (line > 0 && afterWhiteSpace.length() > 0 ) { createWhiteSpace(whiteSpaceLength + shift, buffer); buffer.append(afterWhiteSpace); } myDocument.replaceString(elementRange.getStartOffset(), elementRange.getEndOffset(), buffer.toString()); return buffer.length(); }