| 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.selection; | 5 library trydart.selection; |
| 6 | 6 |
| 7 import 'dart:html' show | 7 import 'dart:html' show |
| 8 CharacterData, | 8 CharacterData, |
| 9 Element, | 9 Element, |
| 10 Node, | 10 Node, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 TrySelection.empty(this.root) | 35 TrySelection.empty(this.root) |
| 36 : anchorNode = null, | 36 : anchorNode = null, |
| 37 anchorOffset = -1; | 37 anchorOffset = -1; |
| 38 | 38 |
| 39 Text addNodeFromSubstring(int start, | 39 Text addNodeFromSubstring(int start, |
| 40 int end, | 40 int end, |
| 41 List<Node> nodes, | 41 List<Node> nodes, |
| 42 [Decoration decoration]) { | 42 [Decoration decoration]) { |
| 43 if (start == end) return null; | 43 if (start == end) return null; |
| 44 | 44 |
| 45 Text textNode = new Text(text.substring(start, end)); | 45 String substring = text.substring(start, end); |
| 46 if (substring == '\n') { |
| 47 // Don't add decorations to trailing newline. |
| 48 decoration = null; |
| 49 } |
| 50 Text textNode = new Text(substring); |
| 46 | 51 |
| 47 if (start <= globalOffset && globalOffset <= end) { | 52 if (start <= globalOffset && globalOffset <= end) { |
| 48 anchorNode = textNode; | 53 anchorNode = textNode; |
| 49 anchorOffset = globalOffset - start; | 54 anchorOffset = globalOffset - start; |
| 50 } | 55 } |
| 51 | 56 |
| 52 nodes.add(decoration == null ? textNode : decoration.applyTo(textNode)); | 57 nodes.add(decoration == null ? textNode : decoration.applyTo(textNode)); |
| 53 | 58 |
| 54 return textNode; | 59 return textNode; |
| 55 } | 60 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 }); | 99 }); |
| 95 return found ? offset : -1; | 100 return found ? offset : -1; |
| 96 } | 101 } |
| 97 } | 102 } |
| 98 | 103 |
| 99 bool isCollapsed(Selection selection) { | 104 bool isCollapsed(Selection selection) { |
| 100 // Firefox and Chrome don't agree on if the selection is collapsed if there | 105 // Firefox and Chrome don't agree on if the selection is collapsed if there |
| 101 // is no node selected. | 106 // is no node selected. |
| 102 return selection.isCollapsed && selection.anchorNode != null; | 107 return selection.isCollapsed && selection.anchorNode != null; |
| 103 } | 108 } |
| OLD | NEW |