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

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

Issue 147983005: Improved linebreaking for imports (darbug.com/16366) and non-breaking line support. (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') | no next file with comments »
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 32082)
+++ pkg/analyzer/lib/src/services/formatter_impl.dart (working copy)
@@ -367,7 +367,7 @@
final twoSlashes = new RegExp(r'//[^/]');
/// A weight for potential breakpoints.
- int breakWeight = DEFAULT_SPACE_WEIGHT;
+ int currentBreakWeight = DEFAULT_SPACE_WEIGHT;
/// Original pre-format selection information (may be null).
final Selection preSelection;
@@ -923,7 +923,7 @@
visitImportDirective(ImportDirective node) {
visitNodes(node.metadata, followedBy: newlines);
token(node.keyword);
- space();
+ nonBreakingSpace();
visit(node.uri);
token(node.asToken, precededBy: space, followedBy: space);
allowContinuedLines((){
@@ -1481,11 +1481,11 @@
emitSpaces() {
if (leadingSpaces > 0) {
if (allowLineLeadingSpaces || !writer.currentLine.isWhitespace()) {
- writer.spaces(leadingSpaces, breakWeight: breakWeight);
+ writer.spaces(leadingSpaces, breakWeight: currentBreakWeight);
}
leadingSpaces = 0;
allowLineLeadingSpaces = false;
- breakWeight = DEFAULT_SPACE_WEIGHT;
+ currentBreakWeight = DEFAULT_SPACE_WEIGHT;
}
}
@@ -1503,22 +1503,21 @@
}
}
- /// Emit a non-breakable space. If [allowLineLeading] is specified, spaces
+ /// Emit a non-breakable space.
+ nonBreakingSpace() {
+ space(breakWeight: UNBREAKABLE_SPACE_WEIGHT);
+ }
+
+ /// Emit a space. If [allowLineLeading] is specified, spaces
/// will be preserved at the start of a line (in addition to the
/// indent-level), otherwise line-leading spaces will be ignored.
- space({n: 1, allowLineLeading: false}) {
+ space({n: 1, allowLineLeading: false, breakWeight: DEFAULT_SPACE_WEIGHT}) {
//TODO(pquitslund): replace with a proper space token
leadingSpaces+=n;
allowLineLeadingSpaces = allowLineLeading;
+ currentBreakWeight = breakWeight;
}
- /// Mark a breakable space
- breakableSpace() {
- space();
- breakWeight =
- countNewlinesBetween(previousToken, previousToken.next) > 0 ? 1 : 0;
- }
-
/// Append the given [string] to the source writer if it's non-null.
append(String string) {
if (string != null && !string.isEmpty) {
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/services/writer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698