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 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt' | 9 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt' |
10 show | 10 show |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (anchorNode == node) { | 234 if (anchorNode == node) { |
235 hasSelection = true; | 235 hasSelection = true; |
236 anchorOffset = selection.anchorOffset + offset; | 236 anchorOffset = selection.anchorOffset + offset; |
237 } | 237 } |
238 int newOffset = offset + cdata.length; | 238 int newOffset = offset + cdata.length; |
239 if (offset <= begin && begin < newOffset) { | 239 if (offset <= begin && begin < newOffset) { |
240 hasSelection = node == anchorNode; | 240 hasSelection = node == anchorNode; |
241 anchorOffset = selection.anchorOffset; | 241 anchorOffset = selection.anchorOffset; |
242 Node marker = new Text(""); | 242 Node marker = new Text(""); |
243 node.replaceWith(marker); | 243 node.replaceWith(marker); |
244 // TODO(ahe): Don't highlight everything in the node. Find | 244 // TODO(ahe): Don't highlight everything in the node. Find the |
245 // the relevant token. | 245 // relevant token (works for now as we create a node for each token, |
| 246 // which is probably not great for performance). |
246 if (kind == 'error') { | 247 if (kind == 'error') { |
247 marker.replaceWith(diagnostic(node, error(message))); | 248 marker.replaceWith(diagnostic(node, error(message))); |
248 } else if (kind == 'warning') { | 249 } else if (kind == 'warning') { |
249 marker.replaceWith(diagnostic(node, warning(message))); | 250 marker.replaceWith(diagnostic(node, warning(message))); |
250 } else { | 251 } else { |
251 marker.replaceWith(diagnostic(node, info(message))); | 252 marker.replaceWith(diagnostic(node, info(message))); |
252 } | 253 } |
253 if (hasSelection) { | 254 if (hasSelection) { |
254 selection.collapse(node, anchorOffset); | 255 selection.collapse(node, anchorOffset); |
255 } | 256 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 String tokenValue = token.value; | 295 String tokenValue = token.value; |
295 String tokenInfo = token.info.value; | 296 String tokenInfo = token.info.value; |
296 if (tokenInfo == 'string') return currentTheme.string; | 297 if (tokenInfo == 'string') return currentTheme.string; |
297 // if (tokenInfo == 'identifier') return identifier; | 298 // if (tokenInfo == 'identifier') return identifier; |
298 if (tokenInfo == 'keyword') return currentTheme.keyword; | 299 if (tokenInfo == 'keyword') return currentTheme.keyword; |
299 if (tokenInfo == 'comment') return currentTheme.singleLineComment; | 300 if (tokenInfo == 'comment') return currentTheme.singleLineComment; |
300 if (tokenInfo == 'malformed input') { | 301 if (tokenInfo == 'malformed input') { |
301 isMalformedInput = true; | 302 isMalformedInput = true; |
302 return new DiagnosticDecoration('error', tokenValue); | 303 return new DiagnosticDecoration('error', tokenValue); |
303 } | 304 } |
304 return null; | 305 return currentTheme.foreground; |
305 } | 306 } |
306 | 307 |
307 diagnostic(text, tip) { | 308 diagnostic(text, tip) { |
308 if (text is String) { | 309 if (text is String) { |
309 text = new Text(text); | 310 text = new Text(text); |
310 } | 311 } |
311 return new AnchorElement() | 312 return new AnchorElement() |
312 ..classes.add('diagnostic') | 313 ..classes.add('diagnostic') |
313 ..append(text) | 314 ..append(text) |
314 ..append(tip); | 315 ..append(tip); |
315 } | 316 } |
OLD | NEW |