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; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 event.preventDefault(); | 383 event.preventDefault(); |
384 Node node = selection.anchorNode; | 384 Node node = selection.anchorNode; |
385 if (node is Text) { | 385 if (node is Text) { |
386 Text text = node; | 386 Text text = node; |
387 int offset = selection.anchorOffset; | 387 int offset = selection.anchorOffset; |
388 // If at end-of-file, insert an extra newline. The the extra | 388 // If at end-of-file, insert an extra newline. The the extra |
389 // newline ensures that the next line isn't empty. At least Chrome | 389 // newline ensures that the next line isn't empty. At least Chrome |
390 // behaves as if "\n" is just a single line. "\nc" (where c is any | 390 // behaves as if "\n" is just a single line. "\nc" (where c is any |
391 // character) is two lines, according to Chrome. | 391 // character) is two lines, according to Chrome. |
392 String newline = isAtEndOfFile(text, offset) ? '\n\n' : '\n'; | 392 String newline = isAtEndOfFile(text, offset) ? '\n\n' : '\n'; |
393 text.insertData(offset, newline); | 393 text.insertData(offset, newline); |
ahe
2014/08/22 09:46:52
Does this work the same in IE and Chrome? If so, c
aam-me
2014/08/22 12:05:14
I believe it does, but appendText is on Element, w
| |
394 selection.collapse(text, offset + 1); | 394 selection.collapse(text, offset + 1); |
395 } else if (node is Element) { | 395 } else if (node is Element) { |
396 node.appendText('\n\n'); | 396 node.appendText('\n\n'); |
397 selection.collapse(node.firstChild, 1); | 397 if (node.firstChild is Text) { |
398 selection.collapse(node.firstChild, 1); | |
399 } else { | |
400 // This else-branch accomodates IE11, which | |
401 // puts <BR> instead of '\n' in content-editable Divs. | |
402 selection.collapse(node, 1); | |
ahe
2014/08/22 09:46:52
How does this interact with getText in shadow_root
aam-me
2014/08/22 12:05:14
By the time we get to that getText <br>'s are gone
ahe
2014/08/22 12:13:44
In other words, this wouldn't work if IE supported
| |
403 } | |
398 } else { | 404 } else { |
399 window.console | 405 window.console |
400 ..error('Unexpected node') | 406 ..error('Unexpected node') |
401 ..dir(node); | 407 ..dir(node); |
402 } | 408 } |
403 } | 409 } |
404 break; | 410 break; |
405 } | 411 } |
406 case KeyCode.TAB: { | 412 case KeyCode.TAB: { |
407 Selection selection = window.getSelection(); | 413 Selection selection = window.getSelection(); |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1347 token = token.next; | 1353 token = token.next; |
1348 kind = token.kind; | 1354 kind = token.kind; |
1349 } | 1355 } |
1350 return token; | 1356 return token; |
1351 } | 1357 } |
1352 | 1358 |
1353 String extractQuote(String string) { | 1359 String extractQuote(String string) { |
1354 StringQuoting q = StringValidator.quotingFromString(string); | 1360 StringQuoting q = StringValidator.quotingFromString(string); |
1355 return (q.raw ? 'r' : '') + (q.quoteChar * q.leftQuoteLength); | 1361 return (q.raw ? 'r' : '') + (q.quoteChar * q.leftQuoteLength); |
1356 } | 1362 } |
OLD | NEW |