| 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 trydart.editor; | 5 library trydart.editor; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'package:compiler/implementation/scanner/scannerlib.dart' | 9 import 'package:compiler/implementation/scanner/scannerlib.dart' |
| 10 show | 10 show |
| 11 EOF_TOKEN, | 11 EOF_TOKEN, |
| 12 StringScanner, | 12 StringScanner, |
| 13 Token; | 13 Token; |
| 14 | 14 |
| 15 import 'ui.dart' show | 15 import 'ui.dart' show |
| 16 currentTheme, | 16 currentTheme, |
| 17 hackDiv, | 17 hackDiv, |
| 18 inputPre, | 18 mainEditorPane, |
| 19 observer, | 19 observer, |
| 20 outputDiv; | 20 outputDiv; |
| 21 | 21 |
| 22 import 'decoration.dart' show | 22 import 'decoration.dart' show |
| 23 CodeCompletionDecoration, | 23 CodeCompletionDecoration, |
| 24 Decoration, | 24 Decoration, |
| 25 DiagnosticDecoration, | 25 DiagnosticDecoration, |
| 26 error, | 26 error, |
| 27 info, | 27 info, |
| 28 warning; | 28 warning; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 var activeCompletion; | 102 var activeCompletion; |
| 103 num minSuggestionWidth = 0; | 103 num minSuggestionWidth = 0; |
| 104 | 104 |
| 105 /// Returns the [Element] which encloses the current collapsed selection, if it | 105 /// Returns the [Element] which encloses the current collapsed selection, if it |
| 106 /// exists. | 106 /// exists. |
| 107 Element getElementAtSelection() { | 107 Element getElementAtSelection() { |
| 108 Selection selection = window.getSelection(); | 108 Selection selection = window.getSelection(); |
| 109 if (!selection.isCollapsed) return null; | 109 if (!selection.isCollapsed) return null; |
| 110 var anchorNode = selection.anchorNode; | 110 var anchorNode = selection.anchorNode; |
| 111 if (!inputPre.contains(anchorNode)) return null; | 111 if (!mainEditorPane.contains(anchorNode)) return null; |
| 112 if (inputPre == anchorNode) return null; | 112 if (mainEditorPane == anchorNode) return null; |
| 113 int type = anchorNode.nodeType; | 113 int type = anchorNode.nodeType; |
| 114 if (type != Node.TEXT_NODE) return null; | 114 if (type != Node.TEXT_NODE) return null; |
| 115 Text text = anchorNode; | 115 Text text = anchorNode; |
| 116 var parent = text.parent; | 116 var parent = text.parent; |
| 117 if (parent is! Element) return null; | 117 if (parent is! Element) return null; |
| 118 if (inputPre == parent) return null; | 118 if (mainEditorPane == parent) return null; |
| 119 return parent; | 119 return parent; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool isMalformedInput = false; | 122 bool isMalformedInput = false; |
| 123 String currentSource = ""; | 123 String currentSource = ""; |
| 124 | 124 |
| 125 addDiagnostic(String kind, String message, int begin, int end) { | 125 addDiagnostic(String kind, String message, int begin, int end) { |
| 126 observer.disconnect(); | 126 observer.disconnect(); |
| 127 Selection selection = window.getSelection(); | 127 Selection selection = window.getSelection(); |
| 128 int offset = 0; | 128 int offset = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 var child = node.firstChild; | 175 var child = node.firstChild; |
| 176 while(child != null && !foundNode) { | 176 while(child != null && !foundNode) { |
| 177 walk4(child); | 177 walk4(child); |
| 178 child = child.nextNode; | 178 child = child.nextNode; |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 walk4(inputPre); | 181 walk4(mainEditorPane); |
| 182 | 182 |
| 183 if (!foundNode) { | 183 if (!foundNode) { |
| 184 outputDiv.appendText('$message\n'); | 184 outputDiv.appendText('$message\n'); |
| 185 } | 185 } |
| 186 | 186 |
| 187 observer.takeRecords(); | 187 observer.takeRecords(); |
| 188 observer.observe( | 188 observer.observe( |
| 189 inputPre, childList: true, characterData: true, subtree: true); | 189 mainEditorPane, childList: true, characterData: true, subtree: true); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void inlineChildren(Element element) { | 192 void inlineChildren(Element element) { |
| 193 if (element == null) return; | 193 if (element == null) return; |
| 194 var parent = element.parentNode; | 194 var parent = element.parentNode; |
| 195 if (parent == null) return; | 195 if (parent == null) return; |
| 196 for (Node child in new List.from(element.nodes)) { | 196 for (Node child in new List.from(element.nodes)) { |
| 197 child.remove(); | 197 child.remove(); |
| 198 parent.insertBefore(child, element); | 198 parent.insertBefore(child, element); |
| 199 } | 199 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 219 | 219 |
| 220 diagnostic(text, tip) { | 220 diagnostic(text, tip) { |
| 221 if (text is String) { | 221 if (text is String) { |
| 222 text = new Text(text); | 222 text = new Text(text); |
| 223 } | 223 } |
| 224 return new AnchorElement() | 224 return new AnchorElement() |
| 225 ..classes.add('diagnostic') | 225 ..classes.add('diagnostic') |
| 226 ..append(text) | 226 ..append(text) |
| 227 ..append(tip); | 227 ..append(tip); |
| 228 } | 228 } |
| OLD | NEW |