Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library script_inset_element; | 5 library script_inset_element; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'observatory_element.dart'; | 8 import 'observatory_element.dart'; |
| 9 import 'package:observatory/service.dart'; | 9 import 'package:observatory/service.dart'; |
| 10 import 'package:polymer/polymer.dart'; | 10 import 'package:polymer/polymer.dart'; |
| 11 | 11 |
| 12 class ScriptElipsis { | |
| 13 ScriptElipsis(this.start, this.end); | |
| 14 int line = null; | |
|
Cutch
2015/01/15 21:58:16
remove this
| |
| 15 | |
| 16 final int start; | |
| 17 final int end; | |
| 18 } | |
| 19 | |
| 12 /// Box with script source code in it. | 20 /// Box with script source code in it. |
| 13 @CustomTag('script-inset') | 21 @CustomTag('script-inset') |
| 14 class ScriptInsetElement extends ObservatoryElement { | 22 class ScriptInsetElement extends ObservatoryElement { |
| 15 @published Script script; | 23 @published Script script; |
| 16 | 24 |
| 17 /// Set the height to make the script inset scroll. Otherwise it | 25 /// Set the height to make the script inset scroll. Otherwise it |
| 18 /// will show from startPos to endPos. | 26 /// will show from startPos to endPos. |
| 19 @published String height = null; | 27 @published String height = null; |
| 20 | 28 |
| 21 @published int currentPos; | 29 @published int currentPos; |
| 22 @published int startPos; | 30 @published int startPos; |
| 23 @published int endPos; | 31 @published int endPos; |
| 24 | 32 |
| 25 @observable int currentLine; | 33 @observable int currentLine; |
| 26 @observable int startLine; | 34 @observable int startLine; |
| 27 @observable int endLine; | 35 @observable int endLine; |
| 28 @observable bool linesReady = false; | 36 @observable bool linesReady = false; |
| 29 | 37 |
| 30 @observable List<ScriptLine> lines = toObservable([]); | 38 // Contents are either ScriptLine or ScriptElipsis. |
| 39 @observable List lines = toObservable([]); | |
| 31 | 40 |
| 32 String makeLineId(int line) { | 41 String makeLineId(int line) { |
| 33 return 'line-$line'; | 42 return 'line-$line'; |
| 34 } | 43 } |
| 35 | 44 |
| 36 MutationObserver _observer; | 45 MutationObserver _observer; |
| 37 | 46 |
| 38 void _scrollToCurrentPos() { | 47 void _scrollToCurrentPos() { |
| 39 var line = shadowRoot.querySelector('#line-$currentLine'); | 48 var line = shadowRoot.querySelector('#line-$currentLine'); |
| 40 if (line != null) { | 49 if (line != null) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 ? script.tokenToLine(startPos) | 114 ? script.tokenToLine(startPos) |
| 106 : 1); | 115 : 1); |
| 107 currentLine = (currentPos != null | 116 currentLine = (currentPos != null |
| 108 ? script.tokenToLine(currentPos) | 117 ? script.tokenToLine(currentPos) |
| 109 : null); | 118 : null); |
| 110 endLine = (endPos != null | 119 endLine = (endPos != null |
| 111 ? script.tokenToLine(endPos) | 120 ? script.tokenToLine(endPos) |
| 112 : script.lines.length); | 121 : script.lines.length); |
| 113 | 122 |
| 114 lines.clear(); | 123 lines.clear(); |
| 124 int blankLineCount = 0; | |
| 115 for (int i = (startLine - 1); i <= (endLine - 1); i++) { | 125 for (int i = (startLine - 1); i <= (endLine - 1); i++) { |
| 116 lines.add(script.lines[i]); | 126 if (script.lines[i].isBlank) { |
| 127 // Try to introduce elipses if there are 4 or more contiguous blank line s. | |
| 128 blankLineCount++; | |
| 129 } else { | |
| 130 if (blankLineCount > 0) { | |
| 131 int firstBlank = i - blankLineCount; | |
| 132 int lastBlank = i - 1; | |
| 133 if (blankLineCount < 4) { | |
| 134 // Too few blank lines for an elipsis. | |
| 135 for (int j = firstBlank; j <= lastBlank; j++) { | |
| 136 lines.add(script.lines[j]); | |
| 137 } | |
| 138 } else { | |
| 139 // Add an elipsis for the skipped region. | |
| 140 lines.add(script.lines[firstBlank]); | |
| 141 lines.add(new ScriptElipsis(firstBlank + 1, lastBlank - 1)); | |
| 142 lines.add(script.lines[lastBlank]); | |
| 143 } | |
| 144 blankLineCount = 0; | |
| 145 } | |
| 146 lines.add(script.lines[i]); | |
| 147 } | |
| 117 } | 148 } |
| 118 linesReady = true; | 149 linesReady = true; |
| 119 } | 150 } |
| 120 | 151 |
| 121 ScriptInsetElement.created() : super.created(); | 152 ScriptInsetElement.created() : super.created(); |
| 122 } | 153 } |
| 123 | 154 |
| 124 @CustomTag('breakpoint-toggle') | 155 @CustomTag('breakpoint-toggle') |
| 125 class BreakpointToggleElement extends ObservatoryElement { | 156 class BreakpointToggleElement extends ObservatoryElement { |
| 126 @published ScriptLine line; | 157 @published ScriptLine line; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 139 } else { | 170 } else { |
| 140 // Existing breakpoint. Remove it. | 171 // Existing breakpoint. Remove it. |
| 141 line.script.isolate.clearBreakpoint(line.bpt).then((_) { | 172 line.script.isolate.clearBreakpoint(line.bpt).then((_) { |
| 142 busy = false; | 173 busy = false; |
| 143 }); | 174 }); |
| 144 } | 175 } |
| 145 } | 176 } |
| 146 | 177 |
| 147 BreakpointToggleElement.created() : super.created(); | 178 BreakpointToggleElement.created() : super.created(); |
| 148 } | 179 } |
| OLD | NEW |