| 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 /// Box with script source code in it. | 12 /// Box with script source code in it. |
| 13 @CustomTag('script-inset') | 13 @CustomTag('script-inset') |
| 14 class ScriptInsetElement extends ObservatoryElement { | 14 class ScriptInsetElement extends ObservatoryElement { |
| 15 @published Script script; | 15 @published Script script; |
| 16 | 16 |
| 17 /// Set the height to make the script inset scroll. Otherwise it | 17 /// Set the height to make the script inset scroll. Otherwise it |
| 18 /// will show from startPos to endPos. | 18 /// will show from startPos to endPos. |
| 19 @published String height = null; | 19 @published String height = null; |
| 20 | 20 |
| 21 @published int currentPos; | 21 @published int currentPos; |
| 22 @published int startPos; | 22 @published int startPos; |
| 23 @published int endPos; | 23 @published int endPos; |
| 24 | 24 |
| 25 @observable int currentLine; | 25 @observable int currentLine; |
| 26 @observable int currentCol; |
| 26 @observable int startLine; | 27 @observable int startLine; |
| 27 @observable int endLine; | 28 @observable int endLine; |
| 28 @observable bool linesReady = false; | 29 @observable bool linesReady = false; |
| 29 | 30 |
| 30 // Contents are either ScriptLine or ScriptElipsis. | 31 // Contents are either ScriptLine or ScriptElipsis. |
| 31 @observable List lines = toObservable([]); | 32 @observable List lines = toObservable([]); |
| 32 | 33 |
| 33 String makeLineId(int line) { | 34 String makeLineId(int line) { |
| 34 return 'line-$line'; | 35 return 'line-$line'; |
| 35 } | 36 } |
| 36 | 37 |
| 38 String clip(String line, int start, [int limit]) { |
| 39 try { |
| 40 return line.substring(start, limit); |
| 41 } catch (_) { |
| 42 // NOTE(turnidge): Sometimes polymer updates give us garbage |
| 43 // starts and limits during page updates. |
| 44 return "OOB"; |
| 45 } |
| 46 } |
| 47 |
| 37 MutationObserver _observer; | 48 MutationObserver _observer; |
| 38 | 49 |
| 39 void _scrollToCurrentPos() { | 50 void _scrollToCurrentPos() { |
| 40 var line = shadowRoot.querySelector('#line-$currentLine'); | 51 var line = shadowRoot.querySelector('#line-$currentLine'); |
| 41 if (line != null) { | 52 if (line != null) { |
| 42 line.scrollIntoView(); | 53 line.scrollIntoView(); |
| 43 } | 54 } |
| 44 } | 55 } |
| 45 | 56 |
| 46 void _onMutation(mutations, observer) { | 57 void _onMutation(mutations, observer) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 112 } |
| 102 }); | 113 }); |
| 103 return; | 114 return; |
| 104 } | 115 } |
| 105 startLine = (startPos != null | 116 startLine = (startPos != null |
| 106 ? script.tokenToLine(startPos) | 117 ? script.tokenToLine(startPos) |
| 107 : 1); | 118 : 1); |
| 108 currentLine = (currentPos != null | 119 currentLine = (currentPos != null |
| 109 ? script.tokenToLine(currentPos) | 120 ? script.tokenToLine(currentPos) |
| 110 : null); | 121 : null); |
| 122 currentCol = (currentPos != null |
| 123 ? (script.tokenToCol(currentPos) - 1) // make this 0-based. |
| 124 : null); |
| 111 endLine = (endPos != null | 125 endLine = (endPos != null |
| 112 ? script.tokenToLine(endPos) | 126 ? script.tokenToLine(endPos) |
| 113 : script.lines.length); | 127 : script.lines.length); |
| 114 | 128 |
| 115 lines.clear(); | 129 lines.clear(); |
| 116 int blankLineCount = 0; | 130 int blankLineCount = 0; |
| 117 for (int i = (startLine - 1); i <= (endLine - 1); i++) { | 131 for (int i = (startLine - 1); i <= (endLine - 1); i++) { |
| 118 if (script.lines[i].isBlank) { | 132 if (script.lines[i].isBlank) { |
| 119 // Try to introduce elipses if there are 4 or more contiguous blank line
s. | 133 // Try to introduce elipses if there are 4 or more contiguous blank line
s. |
| 120 blankLineCount++; | 134 blankLineCount++; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } else { | 176 } else { |
| 163 // Existing breakpoint. Remove it. | 177 // Existing breakpoint. Remove it. |
| 164 line.script.isolate.removeBreakpoint(line.bpt).then((_) { | 178 line.script.isolate.removeBreakpoint(line.bpt).then((_) { |
| 165 busy = false; | 179 busy = false; |
| 166 }); | 180 }); |
| 167 } | 181 } |
| 168 } | 182 } |
| 169 | 183 |
| 170 BreakpointToggleElement.created() : super.created(); | 184 BreakpointToggleElement.created() : super.created(); |
| 171 } | 185 } |
| OLD | NEW |