mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -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:
parent
0412ece8ec
commit
a9a0ac6411
4 changed files with 17 additions and 12 deletions
File diff suppressed because one or more lines are too long
|
@ -154,6 +154,13 @@
|
||||||
var getSelection = function () {
|
var getSelection = function () {
|
||||||
if ( sel.rangeCount ) {
|
if ( sel.rangeCount ) {
|
||||||
lastSelection = sel.getRangeAt( 0 ).cloneRange();
|
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;
|
return lastSelection;
|
||||||
};
|
};
|
||||||
|
|
|
@ -108,7 +108,7 @@ implement( window.Node ? [ Node ] : [ Text, Element, HTMLDocument ], {
|
||||||
});
|
});
|
||||||
|
|
||||||
implement([ Text ], {
|
implement([ Text ], {
|
||||||
isLeaf: $True,
|
isLeaf: $False,
|
||||||
isInline: $True,
|
isInline: $True,
|
||||||
getLength: function () {
|
getLength: function () {
|
||||||
return this.length;
|
return this.length;
|
||||||
|
@ -388,7 +388,7 @@ implement([ Element ], {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( useTextFixer ) {
|
if ( useTextFixer ) {
|
||||||
while ( !el.isLeaf() ) {
|
while ( el.nodeType !== TEXT_NODE && !el.isLeaf() ) {
|
||||||
child = el.firstChild;
|
child = el.firstChild;
|
||||||
if ( !child ) {
|
if ( !child ) {
|
||||||
fixer = doc.createTextNode( '' );
|
fixer = doc.createTextNode( '' );
|
||||||
|
@ -396,16 +396,14 @@ implement([ Element ], {
|
||||||
}
|
}
|
||||||
el = child;
|
el = child;
|
||||||
}
|
}
|
||||||
if ( el.isLeaf() ) {
|
if ( el.nodeType === TEXT_NODE ) {
|
||||||
if ( el.nodeType !== TEXT_NODE ) {
|
|
||||||
el.parentNode.insertBefore(
|
|
||||||
doc.createTextNode( '' ), el );
|
|
||||||
}
|
|
||||||
// Opera will collapse the block element if it contains
|
// Opera will collapse the block element if it contains
|
||||||
// just spaces (but not if it contains no data at all).
|
// just spaces (but not if it contains no data at all).
|
||||||
else if ( /^ +$/.test( el.data ) ) {
|
if ( /^ +$/.test( el.data ) ) {
|
||||||
el.data = '';
|
el.data = '';
|
||||||
}
|
}
|
||||||
|
} else if ( el.isLeaf() ) {
|
||||||
|
el.parentNode.insertBefore( doc.createTextNode( '' ), el );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( !el.querySelector( 'BR' ) ) {
|
else if ( !el.querySelector( 'BR' ) ) {
|
||||||
|
|
|
@ -344,7 +344,7 @@ implement( Range.prototype, {
|
||||||
|
|
||||||
while ( startContainer.nodeType !== TEXT_NODE ) {
|
while ( startContainer.nodeType !== TEXT_NODE ) {
|
||||||
child = startContainer.childNodes[ startOffset ];
|
child = startContainer.childNodes[ startOffset ];
|
||||||
if ( !child || child.nodeName === 'BR' ) {
|
if ( !child || child.isLeaf() ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
startContainer = child;
|
startContainer = child;
|
||||||
|
@ -353,7 +353,7 @@ implement( Range.prototype, {
|
||||||
if ( endOffset ) {
|
if ( endOffset ) {
|
||||||
while ( endContainer.nodeType !== TEXT_NODE ) {
|
while ( endContainer.nodeType !== TEXT_NODE ) {
|
||||||
child = endContainer.childNodes[ endOffset - 1 ];
|
child = endContainer.childNodes[ endOffset - 1 ];
|
||||||
if ( !child || child.nodeName === 'BR' ) {
|
if ( !child || child.isLeaf() ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
endContainer = child;
|
endContainer = child;
|
||||||
|
@ -362,7 +362,7 @@ implement( Range.prototype, {
|
||||||
} else {
|
} else {
|
||||||
while ( endContainer.nodeType !== TEXT_NODE ) {
|
while ( endContainer.nodeType !== TEXT_NODE ) {
|
||||||
child = endContainer.firstChild;
|
child = endContainer.firstChild;
|
||||||
if ( !child || child.nodeName === 'BR' ) {
|
if ( !child || child.isLeaf() ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
endContainer = child;
|
endContainer = child;
|
||||||
|
|
Loading…
Reference in a new issue