Skip to content

Commit d4b3f0d

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Fix an off-by-one bug with column limit handling for text blocks
PiperOrigin-RevId: 695348215
1 parent 81e9e1c commit d4b3f0d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ private void indentTextBlocks(
205205
initialLines.get(1).stripTrailing().length() - lines.get(0).stripTrailing().length();
206206

207207
String prefix =
208-
(deindent == 0 || lines.stream().anyMatch(x -> x.length() + startColumn > columnLimit))
208+
(deindent == 0
209+
|| lines.stream().anyMatch(x -> x.length() + startColumn - 1 > columnLimit))
209210
? ""
210211
: " ".repeat(startColumn - 1);
211212

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class T {
2+
String a =
3+
"""
4+
# No implicit input file, because they can only be created outside a symbolic macro,
5+
""";
6+
7+
String b =
8+
"""
9+
# No implicit input file, because they can only be created outside a symbolic macro,
10+
""";
11+
String c =
12+
"""
13+
# No implicit input file, because they can only be created outside a symbolic macro,
14+
""";
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class T {
2+
String a =
3+
"""
4+
# No implicit input file, because they can only be created outside a symbolic macro,
5+
""";
6+
7+
String b =
8+
"""
9+
# No implicit input file, because they can only be created outside a symbolic macro,
10+
""";
11+
String c =
12+
"""
13+
# No implicit input file, because they can only be created outside a symbolic macro,
14+
""";
15+
}

0 commit comments

Comments
 (0)