Permalink
Browse files

BRs aren't the only elements that shouldn't act as a range endpoint. …

…Any element that can't have children are in the same boat.

R=nnaze
DELTA=6 (3 added, 0 deleted, 3 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6197


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2467 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent dc31915 commit 7a4771b82504369783a504a25cef8113ebbfaf80 pappy@google.com committed Jan 25, 2013
Showing with 6 additions and 3 deletions.
  1. +3 −0 closure/goog/dom/dom.js
  2. +3 −3 closure/goog/dom/textrange.js
View
@@ -882,6 +882,9 @@ goog.dom.isCss1CompatMode_ = function(doc) {
* console.log(a.innerHTML); // Chrome: "", IE9: "foobar", FF3.5: "foobar"
* </pre>
*
+ * For more information, see:
+ * http://dev.w3.org/html5/markup/syntax.html#syntax-elements
+ *
* TODO(user): Rename shouldAllowChildren() ?
*
* @param {Node} node The node to check.
@@ -113,14 +113,14 @@ goog.dom.TextRange.createFromNodes = function(anchorNode, anchorOffset,
range.isReversed_ = goog.dom.Range.isReversed(anchorNode, anchorOffset,
focusNode, focusOffset);
- // Avoid selecting BRs directly
- if (anchorNode.tagName == 'BR') {
+ // Avoid selecting terminal elements directly
+ if (goog.dom.isElement(anchorNode) && !goog.dom.canHaveChildren(anchorNode)) {
var parent = anchorNode.parentNode;
anchorOffset = goog.array.indexOf(parent.childNodes, anchorNode);
anchorNode = parent;
}
- if (focusNode.tagName == 'BR') {
+ if (goog.dom.isElement(focusNode) && !goog.dom.canHaveChildren(focusNode)) {
var parent = focusNode.parentNode;
focusOffset = goog.array.indexOf(parent.childNodes, focusNode);
focusNode = parent;

0 comments on commit 7a4771b

Please sign in to comment.