| 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 Node, | 9 Node, |
| 10 NodeFilter, | 10 NodeFilter, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 anchorOffset = isCollapsed(selection) ? selection.anchorOffset : -1; | 27 anchorOffset = isCollapsed(selection) ? selection.anchorOffset : -1; |
| 28 | 28 |
| 29 Text addNodeFromSubstring(int start, | 29 Text addNodeFromSubstring(int start, |
| 30 int end, | 30 int end, |
| 31 List<Node> nodes, | 31 List<Node> nodes, |
| 32 [Decoration decoration]) { | 32 [Decoration decoration]) { |
| 33 if (start == end) return null; | 33 if (start == end) return null; |
| 34 | 34 |
| 35 Text textNode = new Text(text.substring(start, end)); | 35 Text textNode = new Text(text.substring(start, end)); |
| 36 | 36 |
| 37 if (start <= globalOffset && globalOffset < end) { | 37 if (start <= globalOffset && globalOffset <= end) { |
| 38 anchorNode = textNode; | 38 anchorNode = textNode; |
| 39 anchorOffset = globalOffset - start; | 39 anchorOffset = globalOffset - start; |
| 40 } | 40 } |
| 41 | 41 |
| 42 nodes.add(decoration == null ? textNode : decoration.applyTo(textNode)); | 42 nodes.add(decoration == null ? textNode : decoration.applyTo(textNode)); |
| 43 | 43 |
| 44 return textNode; | 44 return textNode; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void adjust(Selection selection) { | 47 void adjust(Selection selection) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 73 | 73 |
| 74 return -1; | 74 return -1; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool isCollapsed(Selection selection) { | 78 bool isCollapsed(Selection selection) { |
| 79 // Firefox and Chrome don't agree on if the selection is collapsed if there | 79 // Firefox and Chrome don't agree on if the selection is collapsed if there |
| 80 // is no node selected. | 80 // is no node selected. |
| 81 return selection.isCollapsed && selection.anchorNode != null; | 81 return selection.isCollapsed && selection.anchorNode != null; |
| 82 } | 82 } |
| OLD | NEW |