Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: pkg/analyzer/lib/src/services/formatter_impl.dart

Issue 132383002: Line-breaking plumbing and bits and pieces. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/services/writer.dart » ('j') | pkg/analyzer/lib/src/services/writer.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/services/formatter_impl.dart
===================================================================
--- pkg/analyzer/lib/src/services/formatter_impl.dart (revision 31664)
+++ pkg/analyzer/lib/src/services/formatter_impl.dart (working copy)
@@ -366,6 +366,9 @@
/// Used for matching EOL comments
final twoSlashes = new RegExp(r'//[^/]');
+ /// A weight for potential breakpoints.
+ int breakWeight = null;
+
/// Original pre-format selection information (may be null).
final Selection preSelection;
@@ -995,7 +998,7 @@
visit(node.typeArguments);
token(node.leftBracket);
indent();
- visitCommaSeparatedNodes(node.elements);
+ visitCommaSeparatedNodes(node.elements /*, followedBy: breakableSpace*/);
optionalTrailingComma(node.rightBracket);
unindent();
token(node.rightBracket);
@@ -1455,12 +1458,13 @@
}
emitSpaces() {
- while (leadingSpaces > 0) {
- if (!writer.currentLine.isWhitespace() || allowLineLeadingSpaces) {
- writer.print(' ');
+ if (leadingSpaces > 0) {
+ if (allowLineLeadingSpaces || !writer.currentLine.isWhitespace()) {
+ writer.spaces(leadingSpaces, breakWeight: breakWeight);
}
+ leadingSpaces = 0;
allowLineLeadingSpaces = false;
- leadingSpaces--;
+ breakWeight = null;
}
}
@@ -1487,9 +1491,11 @@
allowLineLeadingSpaces = allowLineLeading;
}
- /// Emit a breakable space
+ /// Mark a breakable space
breakableSpace() {
- //Implement
+ space();
+ breakWeight =
+ countNewlinesBetween(previousToken, previousToken.next) > 0 ? 1 : 0;
}
/// Append the given [string] to the source writer if it's non-null.
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/services/writer.dart » ('j') | pkg/analyzer/lib/src/services/writer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698