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

Unified Diff: dart/site/try/src/selection.dart

Issue 345553008: Fix issues that broke editing on browsers without Shadow DOM support. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Johnni's changes, and fix bugs found during testing. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: dart/site/try/src/selection.dart
diff --git a/dart/site/try/src/selection.dart b/dart/site/try/src/selection.dart
index 641eb7434d4528d1ecd695f9696c5807d42656d1..c0d606eb7d11ff4eb01d1c5e731a914b908cadb3 100644
--- a/dart/site/try/src/selection.dart
+++ b/dart/site/try/src/selection.dart
@@ -6,12 +6,18 @@ library trydart.selection;
import 'dart:html' show
CharacterData,
+ Element,
Node,
NodeFilter,
Selection,
Text,
TreeWalker;
+import 'shadow_root.dart' show
+ WALKER_NEXT,
+ WALKER_RETURN,
+ walkNodes;
+
import 'decoration.dart';
class TrySelection {
@@ -70,18 +76,23 @@ class TrySelection {
if (anchorOffset == -1) return -1;
int offset = 0;
- TreeWalker walker = new TreeWalker(root, NodeFilter.SHOW_TEXT);
- for (Node node = walker.nextNode();
- node != null;
- node = walker.nextNode()) {
- CharacterData text = node;
- if (anchorNode == text) {
- return anchorOffset + offset;
+ bool found = false;
+ walkNodes(root, (Node node) {
+ if (anchorNode == node) {
+ offset += anchorOffset;
+ found = true;
+ return WALKER_RETURN;
}
- offset += text.data.length;
- }
-
- return -1;
+ switch (node.nodeType) {
+ case Node.CDATA_SECTION_NODE:
+ case Node.TEXT_NODE:
+ CharacterData text = node;
+ offset += text.data.length;
+ break;
+ }
+ return WALKER_NEXT;
+ });
+ return found ? offset : -1;
}
}

Powered by Google App Engine
This is Rietveld 408576698