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

Catch and log FF error getting selection.

This commit is contained in:
Neil Jenkins 2013-03-27 16:03:03 +11:00
parent 768f4420b9
commit 02d25f0ef5

View file

@ -163,12 +163,22 @@
lastSelection = sel.getRangeAt( 0 ).cloneRange();
var startContainer = lastSelection.startContainer,
endContainer = lastSelection.endContainer;
// FF can return the selection as being inside an <img>. WTF?
if ( startContainer && startContainer.isLeaf() ) {
lastSelection.setStartBefore( startContainer );
}
if ( endContainer && endContainer.isLeaf() ) {
lastSelection.setEndBefore( endContainer );
// FF sometimes throws an error reading the isLeaf property. Let's
// catch and log it to see if we can find what's going on.
try {
// FF can return the selection as being inside an <img>. WTF?
if ( startContainer && startContainer.isLeaf() ) {
lastSelection.setStartBefore( startContainer );
}
if ( endContainer && endContainer.isLeaf() ) {
lastSelection.setEndBefore( endContainer );
}
} catch ( error ) {
editor.didError({
name: 'Squire#getSelection error',
message: 'Starts: ' + startContainer.nodeName +
'\nEnds: ' + endContainer.nodeName
});
}
}
return lastSelection;