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

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

Issue 285043003: Two related changes that both affect how cursor positions might change on single line edits. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r36207. 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
« no previous file with comments | « dart/site/try/src/interaction_manager.dart ('k') | dart/tests/try/cursor_position_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (anchorOffset >= 0) { 52 if (anchorOffset >= 0) {
53 selection.collapse(anchorNode, anchorOffset); 53 selection.collapse(anchorNode, anchorOffset);
54 } 54 }
55 } 55 }
56 56
57 void updateText(String newText) { 57 void updateText(String newText) {
58 text = newText; 58 text = newText;
59 globalOffset = computeGlobalOffset(root, anchorNode, anchorOffset); 59 globalOffset = computeGlobalOffset(root, anchorNode, anchorOffset);
60 } 60 }
61 61
62 TrySelection copyWithRoot(Node root) {
63 return new TrySelection.empty(root)
64 ..anchorNode = anchorNode
65 ..anchorOffset = anchorOffset;
66 }
67
62 /// Computes the global offset, that is, the offset from [root]. 68 /// Computes the global offset, that is, the offset from [root].
63 static int computeGlobalOffset(Node root, Node anchorNode, int anchorOffset) { 69 static int computeGlobalOffset(Node root, Node anchorNode, int anchorOffset) {
64 if (anchorOffset == -1) return -1; 70 if (anchorOffset == -1) return -1;
65 71
66 int offset = 0; 72 int offset = 0;
67 TreeWalker walker = new TreeWalker(root, NodeFilter.SHOW_TEXT); 73 TreeWalker walker = new TreeWalker(root, NodeFilter.SHOW_TEXT);
68 for (Node node = walker.nextNode(); 74 for (Node node = walker.nextNode();
69 node != null; 75 node != null;
70 node = walker.nextNode()) { 76 node = walker.nextNode()) {
71 CharacterData text = node; 77 CharacterData text = node;
72 if (anchorNode == text) { 78 if (anchorNode == text) {
73 return anchorOffset + offset; 79 return anchorOffset + offset;
74 } 80 }
75 offset += text.data.length; 81 offset += text.data.length;
76 } 82 }
77 83
78 return -1; 84 return -1;
79 } 85 }
80 } 86 }
81 87
82 bool isCollapsed(Selection selection) { 88 bool isCollapsed(Selection selection) {
83 // Firefox and Chrome don't agree on if the selection is collapsed if there 89 // Firefox and Chrome don't agree on if the selection is collapsed if there
84 // is no node selected. 90 // is no node selected.
85 return selection.isCollapsed && selection.anchorNode != null; 91 return selection.isCollapsed && selection.anchorNode != null;
86 } 92 }
OLDNEW
« no previous file with comments | « dart/site/try/src/interaction_manager.dart ('k') | dart/tests/try/cursor_position_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698