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

Unified Diff: lib/src/chunk.dart

Issue 987253002: Separately format lines when a multisplit is split. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Rebase. Created 5 years, 9 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 | lib/src/line_writer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/chunk.dart
diff --git a/lib/src/chunk.dart b/lib/src/chunk.dart
index 58f88af10aba468cbfbca8da3d72f4ea4ad8a83f..e0604275ae4c86cbdeb5ddc628005afd4a624187 100644
--- a/lib/src/chunk.dart
+++ b/lib/src/chunk.dart
@@ -283,7 +283,8 @@ class SplitParam {
/// together, like parameter lists and binary operator expressions.
class Span {
/// Index of the first chunk contained in this span.
- final int start;
+ int get start => _start;
+ int _start;
/// Index of the last chunk contained in this span.
int get end => _end;
@@ -293,7 +294,7 @@ class Span {
/// if the span is for a multisplit.
final int cost;
- Span(this.start, this.cost);
+ Span(this._start, this.cost);
/// Marks this span as ending at [end].
void close(int end) {
@@ -314,6 +315,23 @@ class Span {
return result + ")";
}
+
+ /// Shifts the indexes of the chunk down by [offset].
+ ///
+ /// This is used when a prefix of the chunk list gets pulled off by the
+ /// [LineWriter] after it gets formatted as a line. The remaining spans need
+ /// to have their indices shifted to account for the removed chunks.
+ ///
+ /// Returns `true` if the span has shifted all the way off the front and
+ /// should just be discarded.
+ bool shift(int offset) {
+ if (end != null && end < offset) return true;
+
+ _start -= offset;
+ if (_end != null) _end -= offset;
+
+ return false;
+ }
}
/// A comment in the source, with a bit of information about the surrounding
« no previous file with comments | « no previous file | lib/src/line_writer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698