0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Fix bug where image may be duplicated on enter.

* Do not move range boundaries inside images; these should always be treated as
  leaf nodes.
* Workaround FF bug where it may return range as being inside of image node.
This commit is contained in:
Neil Jenkins 2012-08-01 11:53:37 +10:00
parent 0412ece8ec
commit a9a0ac6411
4 changed files with 17 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -154,6 +154,13 @@
var getSelection = function () {
if ( sel.rangeCount ) {
lastSelection = sel.getRangeAt( 0 ).cloneRange();
// FF can return the selection as being inside an <img>. WTF?
if ( lastSelection.startContainer.isLeaf() ) {
lastSelection.setStartBefore( lastSelection.startContainer );
}
if ( lastSelection.endContainer.isLeaf() ) {
lastSelection.setEndBefore( lastSelection.endContainer );
}
}
return lastSelection;
};

View file

@ -108,7 +108,7 @@ implement( window.Node ? [ Node ] : [ Text, Element, HTMLDocument ], {
});
implement([ Text ], {
isLeaf: $True,
isLeaf: $False,
isInline: $True,
getLength: function () {
return this.length;
@ -388,7 +388,7 @@ implement([ Element ], {
}
} else {
if ( useTextFixer ) {
while ( !el.isLeaf() ) {
while ( el.nodeType !== TEXT_NODE && !el.isLeaf() ) {
child = el.firstChild;
if ( !child ) {
fixer = doc.createTextNode( '' );
@ -396,16 +396,14 @@ implement([ Element ], {
}
el = child;
}
if ( el.isLeaf() ) {
if ( el.nodeType !== TEXT_NODE ) {
el.parentNode.insertBefore(
doc.createTextNode( '' ), el );
}
if ( el.nodeType === TEXT_NODE ) {
// Opera will collapse the block element if it contains
// just spaces (but not if it contains no data at all).
else if ( /^ +$/.test( el.data ) ) {
if ( /^ +$/.test( el.data ) ) {
el.data = '';
}
} else if ( el.isLeaf() ) {
el.parentNode.insertBefore( doc.createTextNode( '' ), el );
}
}
else if ( !el.querySelector( 'BR' ) ) {

View file

@ -344,7 +344,7 @@ implement( Range.prototype, {
while ( startContainer.nodeType !== TEXT_NODE ) {
child = startContainer.childNodes[ startOffset ];
if ( !child || child.nodeName === 'BR' ) {
if ( !child || child.isLeaf() ) {
break;
}
startContainer = child;
@ -353,7 +353,7 @@ implement( Range.prototype, {
if ( endOffset ) {
while ( endContainer.nodeType !== TEXT_NODE ) {
child = endContainer.childNodes[ endOffset - 1 ];
if ( !child || child.nodeName === 'BR' ) {
if ( !child || child.isLeaf() ) {
break;
}
endContainer = child;
@ -362,7 +362,7 @@ implement( Range.prototype, {
} else {
while ( endContainer.nodeType !== TEXT_NODE ) {
child = endContainer.firstChild;
if ( !child || child.nodeName === 'BR' ) {
if ( !child || child.isLeaf() ) {
break;
}
endContainer = child;