Skip to content

Commit

Permalink
Update text block formatting after nickreid's improvements in unknown…
Browse files Browse the repository at this point in the history
… commit

Previously the formatting was adding a forced break at the beginning of text blocks, which caused issues like #1081. With the changes in the baseline CL it correctly handles the 'width' of text blocks containing newlines as infinity, instead of counting the number of characters and treating the newline as having width 1.

Fixes #1081

PiperOrigin-RevId: 620933964
  • Loading branch information
cushon authored and google-java-format Team committed Apr 1, 2024
1 parent 9bdae02 commit 33bf757
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Expand Up @@ -1667,9 +1667,6 @@ public Void visitMemberSelect(MemberSelectTree node, Void unused) {
public Void visitLiteral(LiteralTree node, Void unused) {
sync(node);
String sourceForNode = getSourceForNode(node, getCurrentPath());
if (sourceForNode.startsWith("\"\"\"")) {
builder.forcedBreak();
}
if (isUnaryMinusLiteral(sourceForNode)) {
token("-");
sourceForNode = sourceForNode.substring(1).trim();
Expand Down
Expand Up @@ -40,4 +40,15 @@ class RSLs {
lorem
ipsum
""";
{
f("""
lorem
ipsum
""", 42);

"""
hello %s
"""
.formatted("world");
}
}
Expand Up @@ -51,4 +51,18 @@ ipsum
lorem
ipsum
""";

{
f(
"""
lorem
ipsum
""",
42);

"""
hello %s
"""
.formatted("world");
}
}

0 comments on commit 33bf757

Please sign in to comment.