diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index 8a6fd3c209f3..185d1094f875 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -4482,13 +4482,14 @@ private void preserveIndentation(boolean value) { */ private int getPreservedIndentation(Token token) { int position = token.lineRange().startLine().offset(); - int offset = position % 4; - if (env.currentIndentation % 4 == 0 && env.currentIndentation > position) { + int tabSize = options.getTabSize(); + int offset = position % tabSize; + if (env.currentIndentation % tabSize == 0 && env.currentIndentation > position) { return env.currentIndentation; } if (offset != 0) { if (offset > 2) { - position = position + 4 - offset; + position = position + tabSize - offset; } else { position = position - offset; }