Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: dart/site/try/src/selection.dart

Issue 270703005: Fix source_update_test on Chrome. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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,
11 Selection, 11 Selection,
12 Text, 12 Text,
13 TreeWalker; 13 TreeWalker;
14 14
15 import 'decoration.dart'; 15 import 'decoration.dart';
16 16
17 class TrySelection { 17 class TrySelection {
18 final Node root; 18 final Node root;
19 Node anchorNode; 19 Node anchorNode;
20 int anchorOffset; 20 int anchorOffset;
21 21
22 String text; 22 String text;
23 int globalOffset = -1; 23 int globalOffset = -1;
24 24
25 TrySelection(this.root, Selection selection) 25 TrySelection(this.root, Selection selection)
26 : anchorNode = isCollapsed(selection) ? selection.anchorNode : null, 26 : anchorNode = isCollapsed(selection) ? selection.anchorNode : null,
27 anchorOffset = isCollapsed(selection) ? selection.anchorOffset : -1; 27 anchorOffset = isCollapsed(selection) ? selection.anchorOffset : -1;
28 28
29 TrySelection.empty(this.root)
30 : anchorNode = null,
31 anchorOffset = -1;
32
29 Text addNodeFromSubstring(int start, 33 Text addNodeFromSubstring(int start,
30 int end, 34 int end,
31 List<Node> nodes, 35 List<Node> nodes,
32 [Decoration decoration]) { 36 [Decoration decoration]) {
33 if (start == end) return null; 37 if (start == end) return null;
34 38
35 Text textNode = new Text(text.substring(start, end)); 39 Text textNode = new Text(text.substring(start, end));
36 40
37 if (start <= globalOffset && globalOffset <= end) { 41 if (start <= globalOffset && globalOffset <= end) {
38 anchorNode = textNode; 42 anchorNode = textNode;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 77
74 return -1; 78 return -1;
75 } 79 }
76 } 80 }
77 81
78 bool isCollapsed(Selection selection) { 82 bool isCollapsed(Selection selection) {
79 // Firefox and Chrome don't agree on if the selection is collapsed if there 83 // Firefox and Chrome don't agree on if the selection is collapsed if there
80 // is no node selected. 84 // is no node selected.
81 return selection.isCollapsed && selection.anchorNode != null; 85 return selection.isCollapsed && selection.anchorNode != null;
82 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698