| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.interaction_manager; | 5 library trydart.interaction_manager; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'dart:convert' show | 9 import 'dart:convert' show |
| 10 JSON; | 10 JSON; |
| 11 | 11 |
| 12 import 'dart:math' show | 12 import 'dart:math' show |
| 13 max, | 13 max, |
| 14 min; | 14 min; |
| 15 | 15 |
| 16 import 'dart:async' show | 16 import 'dart:async' show |
| 17 Completer, | 17 Completer, |
| 18 Future, | 18 Future, |
| 19 Timer; | 19 Timer; |
| 20 | 20 |
| 21 import 'dart:collection' show | 21 import 'dart:collection' show |
| 22 Queue; | 22 Queue; |
| 23 | 23 |
| 24 import 'dart:js' as hack; | |
| 25 | |
| 26 import 'package:compiler/implementation/scanner/scannerlib.dart' show | 24 import 'package:compiler/implementation/scanner/scannerlib.dart' show |
| 27 BeginGroupToken, | 25 BeginGroupToken, |
| 28 EOF_TOKEN, | 26 EOF_TOKEN, |
| 29 ErrorToken, | 27 ErrorToken, |
| 30 STRING_INTERPOLATION_IDENTIFIER_TOKEN, | 28 STRING_INTERPOLATION_IDENTIFIER_TOKEN, |
| 31 STRING_INTERPOLATION_TOKEN, | 29 STRING_INTERPOLATION_TOKEN, |
| 32 STRING_TOKEN, | 30 STRING_TOKEN, |
| 33 StringScanner, | 31 StringScanner, |
| 34 Token, | 32 Token, |
| 35 UnmatchedToken, | 33 UnmatchedToken, |
| (...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 message == "Inferring types..." || | 1294 message == "Inferring types..." || |
| 1297 message == "Compiling..." || | 1295 message == "Compiling..." || |
| 1298 message.startsWith('Compiled '); | 1296 message.startsWith('Compiled '); |
| 1299 } | 1297 } |
| 1300 | 1298 |
| 1301 void workAroundFirefoxBug() { | 1299 void workAroundFirefoxBug() { |
| 1302 Selection selection = window.getSelection(); | 1300 Selection selection = window.getSelection(); |
| 1303 if (!isCollapsed(selection)) return; | 1301 if (!isCollapsed(selection)) return; |
| 1304 Node node = selection.anchorNode; | 1302 Node node = selection.anchorNode; |
| 1305 int offset = selection.anchorOffset; | 1303 int offset = selection.anchorOffset; |
| 1306 if (selection.anchorNode is Element && selection.anchorOffset != 0) { | 1304 if (node is Element && offset != 0) { |
| 1307 // In some cases, Firefox reports the wrong anchorOffset (always seems to | 1305 // In some cases, Firefox reports the wrong anchorOffset (always seems to |
| 1308 // be 6) when anchorNode is an Element. Moving the cursor back and forth | 1306 // be 6) when anchorNode is an Element. Moving the cursor back and forth |
| 1309 // adjusts the anchorOffset. | 1307 // adjusts the anchorOffset. |
| 1310 // Safari can also reach this code, but the offset isn't wrong, just | 1308 // Safari can also reach this code, but the offset isn't wrong, just |
| 1311 // inconsistent. After moving the cursor back and forth, Safari will make | 1309 // inconsistent. After moving the cursor back and forth, Safari will make |
| 1312 // the offset relative to a text node. | 1310 // the offset relative to a text node. |
| 1313 // TODO(ahe): Come up with a better way to encapsulate the method below. | 1311 if (settings.hasSelectionModify.value) { |
| 1314 var selectionProxy = new hack.JsObject.fromBrowserObject(selection); | |
| 1315 var modify = selectionProxy['modify']; | |
| 1316 if (modify != null) { | |
| 1317 // IE doesn't support selection.modify, but it's okay since the code | 1312 // IE doesn't support selection.modify, but it's okay since the code |
| 1318 // above is for Firefox, IE doesn't have problems with anchorOffset. | 1313 // above is for Firefox, IE doesn't have problems with anchorOffset. |
| 1319 selection | 1314 selection |
| 1320 ..modify('move', 'backward', 'character') | 1315 ..modify('move', 'backward', 'character') |
| 1321 ..modify('move', 'forward', 'character'); | 1316 ..modify('move', 'forward', 'character'); |
| 1322 print('Selection adjusted $node@$offset -> ' | 1317 print('Selection adjusted $node@$offset -> ' |
| 1323 '${selection.anchorNode}@${selection.anchorOffset}.'); | 1318 '${selection.anchorNode}@${selection.anchorOffset}.'); |
| 1324 } | 1319 } |
| 1325 } | 1320 } |
| 1326 } | 1321 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1347 token = token.next; | 1342 token = token.next; |
| 1348 kind = token.kind; | 1343 kind = token.kind; |
| 1349 } | 1344 } |
| 1350 return token; | 1345 return token; |
| 1351 } | 1346 } |
| 1352 | 1347 |
| 1353 String extractQuote(String string) { | 1348 String extractQuote(String string) { |
| 1354 StringQuoting q = StringValidator.quotingFromString(string); | 1349 StringQuoting q = StringValidator.quotingFromString(string); |
| 1355 return (q.raw ? 'r' : '') + (q.quoteChar * q.leftQuoteLength); | 1350 return (q.raw ? 'r' : '') + (q.quoteChar * q.leftQuoteLength); |
| 1356 } | 1351 } |
| OLD | NEW |