From 7b000293d6fc43786ae1d67fa38c3a62ca0ea25c Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 2 Nov 2011 11:55:08 +1100 Subject: [PATCH] Fix bug in text cursor fixing in IE/Opera. --- source/Node.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/Node.js b/source/Node.js index 35f99af..afc19f1 100644 --- a/source/Node.js +++ b/source/Node.js @@ -29,6 +29,12 @@ var $True = function () { return true; }; var inlineNodeNames = /^(?:A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/; +var leafNodeNames = { + BR: 1, + IMG: 1, + INPUT: 1 +}; + var swap = function( node, node2 ) { var parent = node2.parentNode; if ( parent ) { @@ -134,6 +140,7 @@ implement( Node, { implement( Text, { isInline: $True, + isLeaf: $True, getLength: function () { return this.length; }, @@ -150,6 +157,9 @@ implement( Text, { }); implement( Element, { + isLeaf: function () { + return !!leafNodeNames[ this.nodeName ]; + }, isInline: function () { return inlineNodeNames.test( this.nodeName ); }, @@ -396,7 +406,7 @@ implement( Element, { } } else { if ( useTextFixer ) { - while ( el.nodeType !== TEXT_NODE ) { + while ( !el.isLeaf() ) { child = el.firstChild; if ( !child ) { fixer = doc.createTextNode( '' ); @@ -404,6 +414,9 @@ implement( Element, { } el = child; } + if ( el.isLeaf() && el.nodeType !== TEXT_NODE ) { + el.parentNode.insertBefore( doc.createTextNode( '' ), el ); + } } else if ( !el.textContent && !el.querySelector( 'BR' ) ) { fixer = doc.createElement( 'BR' );